From kromag@nsacom.net Tue May 1 00:06:53 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Mon, 30 Apr 2001 16:06:53 -0700 (PDT) Subject: [Tutor] Breaking threads Message-ID: <200104302306.f3UN6r802577@pop.nsacom.net> Howdy, I am working my way through "Programming Python" from the begining (I have asked too many silly questions! :-). Here is a non-silly question: When I run the following: ----------begin stuff------------------------------ import thread, time glarf=open('\windows\desktop\goat.txt', 'w') def counter(myId, count): for i in range(count): mutex.acquire() # time.sleep(1) glarf.write('[%s]=> %s' % (myId, i)) mutex.release() mutex = thread.allocate_lock() for i in range(10000): thread.start_new_thread(counter, (i, 3)) time.sleep(6) print "Your greasy granny's got holes in her panties. And your main thread is exiting...." --------end stuff--------------- It starts to write 10,000 counts to goat.txt, then dies with the following: Traceback (most recent call last): File "cornfedbeef.py", line 14, in ? thread.start_new_thread(counter, (i, 3)) thread.error: can't start new thread It works fine in iterations of 10, 100 and 1000. Why does it puke at the 10000 mark? Wow! d From arcege@speakeasy.net Tue May 1 00:23:34 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Mon, 30 Apr 2001 19:23:34 -0400 (EDT) Subject: [Tutor] Displaying image in scrolled canvas In-Reply-To: <200104301740.f3UHec821609@pop.nsacom.net> from "kromag@nsacom.net" at Apr 30, 2001 10:40:38 AM Message-ID: <200104302323.f3UNNYf11155@dsl092-074-184.bos1.dsl.speakeasy.net> kromag@nsacom.net wrote > > I am attempting to place a large .gif file into a scrolled canvas. I am > working from the examples in programming python (in case the code looked > slightly familiar :-) > > To wit: Try these changes : > from Tkinter import * > class ScrolledCanvas(Frame): > def __init__(self, parent=None, color='white'): > Frame.__init__(self, parent) > self.pack(expand=YES, fill=BOTH) > photo=PhotoImage(file='\windows\desktop\wacky3.gif') self.photo=PhotoImage(file='\\window\\desktop\\wacky3.gif') > canv = Canvas(self, bg=color, relief=SUNKEN) > canv.config(width=1010, height=745) > canv.config(scrollregion=(0,0,300, 1000)) > canv.create_image(10,10, image=photo, anchor=NW) canv.create_image(10,10, image=self.photo, anchor=NW) > sbar = Scrollbar(self) > sbar.config(command=canv.yview) > canv.config(yscrollcommand=sbar.set) > sbar.pack(side=RIGHT, fill=Y) > canv.pack(side=LEFT, expand=YES, fill=BOTH) > if __name__ == '__main__': ScrolledCanvas().mainloop() > > results in the properly-sized frame and scrollbar, but for some reason the > image does not pop to life. What am I missing here? Image objects in Tkinter need to have the reference kept. Because of a interaction between Tk and Tkinter, when the actual object is destroyed the Tk image is destroyed as well. -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From julieta_rangel@hotmail.com Tue May 1 00:47:53 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Mon, 30 Apr 2001 18:47:53 -0500 Subject: [Tutor] deciphering code Message-ID: Can anyone help me decipher the following code? I know it is to create a polynomial and calculate its derivative, but I would like to know what the lines do, in other words, figure out the purpose for those lines. import string class Poly: def __init__ ( self, v = 'x', c = [0]): """__init__(): Initializes a polynomial Default variable is x Default polynomial is zero""" self.var = v self.coef = c self.deg = len(c)-1 def __str__ (self): """__str__(): Converts a polynomial into a string""" x = `self.coef[0]` for i in range (1, self.deg+1): x = x + " + " + `self.coef[i]` + self.var + "^" + `i` return x def Derivative(p): """Input: an instance of a polynomial Output: a polynomial that is the derivative of the input polynomial Side Effects: None""" pv=p.var pc=[] if p.deg==0: return Poly (v=pv,c=[0]) else: for i in range(0,p.deg): d=(i+1)*p.coef[i+1] pc.append(d) return Poly (v=pv,c=pc) **************************************************************** I'll appreciate any kind of help. Also, what modifications should I make to this code so that a user can input a polynomial and the computer calculates the derivative and displays the answer? Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From julieta_rangel@hotmail.com Tue May 1 01:02:40 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Mon, 30 Apr 2001 19:02:40 -0500 Subject: [Tutor] creating a matrix of unknown dimensions(dimensions depend on input) Message-ID: Right now I'm trying to come up with a program that given a set of elements (at most 30), the computer will determine whether the set is a group or not. (for a set to be a group, the set must be closed under the binary operation in use; the elements of the set must be associative, that is a*(b*c) = (a*b)*c; the set must contain an identity element e such that for any element a on the set, a*e = e*a = a and finally, every element on the set must contain an inverse such that a*a^-1 = e). To do this I want the computer to offer the user a table set up, so that the user can enter the table. Here is where the matrix comes into place. Since I don't know how many elements the set being tested will have, I need to make sure the computer asks the user how many elements the set has, so that the computer can create the matrix, which must be filled out by the user. All the computer has to do know is to check the table (matrix) for all the properties to determine whether the set is a group or not. Does this sound too confusing, anyway, at this point I'm maninly interested on how to create an n x n matrix based on any given input (up to 30elements) Again, any kind of help you can offer will be truly appreciated. Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From julieta_rangel@hotmail.com Tue May 1 01:43:38 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Mon, 30 Apr 2001 19:43:38 -0500 Subject: [Tutor] Having Python figure out whether a set is a group Message-ID: Given the following table, how can I make the computer verify whether the following set is a group or not? The set is G = {e,a,b,ab) The table under the binary operation * with the elements of the set looks like: *_| e a b ab --------------------------- e| e a b ab a| a e ab b b| b ab e a ab| ab b a e The computer would have to check the 4 properties of groups (closure, associativity, identity element, and inverse element). By the way, the set G is in fact a group. It is closed under the binary operation (a * b = ab, and ab is in G, b * ab =a and a is in G, etc), it is associative (a * (b * ab) = (a * b) * ab; e * (a * b) = (e * a) * b, etc), it has an identity element e (a * e = a, b * e = b, ab * e = ab, e * e = e), and every element is an inverse of itself (Note: a*a = e, b*b = e, ab*ab = e, and e*e = e).How could the computer check for closure? I'm assuming the computer would have to go through the elements in the table and compare them with the original set. How could this be done? This problem requires some thinking. Does anyone want to help or do you know where I can go for help? Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From arcege@speakeasy.net Tue May 1 02:16:05 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Mon, 30 Apr 2001 21:16:05 -0400 (EDT) Subject: [Tutor] creating a matrix of unknown dimensions(dimensions depend on input) In-Reply-To: from "Julieta Rangel" at Apr 30, 2001 07:02:40 PM Message-ID: <200105010116.f411G5A16411@dsl092-074-184.bos1.dsl.speakeasy.net> Julieta Rangel wrote > > Right now I'm trying to come up with a program that given a set of elements > (at most 30), the computer will determine whether the set is a group or not. > (for a set to be a group, the set must be closed under the binary > operation in use; the elements of the set must be associative, that is > a*(b*c) = (a*b)*c; the set must contain an identity element e such that for > any element a on the set, a*e = e*a = a > and finally, every element on the set must contain an inverse such that > a*a^-1 = e). To do this I want the computer to offer the user a table set > up, so that the user can enter the table. Here is where the matrix comes > into place. Since I don't know how many elements the set being tested will > have, I need to make sure the computer asks the user how many elements the > set has, so that the computer can create the matrix, which must be filled > out by the user. All the computer has to do know is to check the table > (matrix) for all the properties to determine whether the set is a group or > not. Does this sound too confusing, anyway, at this point I'm maninly > interested on how to create an n x n matrix based on any given input (up to > 30elements) > > Again, any kind of help you can offer will be truly appreciated. If you are just looking for a generic matrix object, then how about: class Matrix: def __init__(self, rows, cols): self.rows = rows self.cols = cols self.table = [0] * (rows * cols) def _getindex(self, x, y): return x + (self.rows * y) def __str__(self): s = '[ ' for j in range(self.cols): base_column = self.rows * j s = s + '[' + str(self.table[base_column]) for i in range(1, self.rows): s = s + ' ' + str(self.table[base_column + i]) s = s + '] ' return s + ']' def __getitem__(self, (x, y)): # make sure that we aren't going beyond our bounds if not (0 <= x < self.rows) or not (0 <= y < self.cols): raise IndexError((x, y)) return self.table[self._getindex(x, y)] def __setitem__(self, (x, y), value): # make sure that we aren't going beyond our bounds if not (0 <= x < self.rows) or not (0 <= y < self.cols): raise IndexError((x, y)) self.table[self._getindex(x, y)] = value while 1: try: (x, y) = input('Enter the dimensions of the matrix (r, c): ') except: pass else: break m = Matrix(x, y) for j in range(m.cols): for i in range(m.rows): m[i, j] = i + j print m More can be added to the class, but it gives you what you seem to be asking for. If you are looking into more complicated mathematics, then I suggest looking into NumPy (Numeric Python) which has a lot of built-in constructs, algorithms and mechanisms. You might also want to look at the numerous math related modules in the Vaults of Parnassus (). -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From dyoo@hkn.eecs.berkeley.edu Tue May 1 02:30:34 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 30 Apr 2001 18:30:34 -0700 (PDT) Subject: [Tutor] creating a matrix of unknown dimensions(dimensions depend on input) In-Reply-To: Message-ID: On Mon, 30 Apr 2001, Julieta Rangel wrote: > Right now I'm trying to come up with a program that given a set of elements > (at most 30), the computer will determine whether the set is a group or not. > a*a^-1 = e). To do this I want the computer to offer the user a table set > up, so that the user can enter the table. Here is where the matrix comes > into place. Since I don't know how many elements the set being tested will > have, I need to make sure the computer asks the user how many elements the > set has, so that the computer can create the matrix, which must be filled > out by the user. All the computer has to do know is to check the table > (matrix) for all the properties to determine whether the set is a group or > not. Does this sound too confusing, anyway, at this point I'm maninly No, this makes sense; so you're making a program that makes it easy to enter in the table that tells us how the operator works on a pair of the group elements. This sounds reasonable. > interested on how to create an n x n matrix based on any given input (up to > 30elements) > > Again, any kind of help you can offer will be truly appreciated. There are a couple of ways to go about this. One way that you might like is the "dictionary" approach. It sounds like we're trying to write something that maps 2-tuples (2 elements) to some element. Whenever we're storing a "mapping", we're thinking of a Python dictionary: ### >>> mytable = {} ## Initially, an empty dictionary >>> mytable[0, 0] = 42 ## Filling in an entry >>> mytable[0, 0] ## Looking up an entry 42 ### (For those who are curious, we're depending on Python's implicit knowledge that by saying "0, 0", we actually mean the tuple "(0, 0)".) This is even nicer than a two-dimensional array, because there isn't any fixed size to the dictionary; you don't even need to preallocate the dimensions. Just start plugging your table values in. Another operation that dictionaries support is telling us which entries we filled in. We do this by asking a dictionary what keys() it has: ### >>> mytable.keys() [(0, 0)] >>> mytable[0, 1] = 3.1415 >>> mytable[1, 0] = 2.718 >>> mytable[1, 1] = 1.61 >>> mytable.keys() [(0, 1), (0, 0), (1, 0), (1, 1)] ### Another really useful thing we can ask a dictionary is a list of it's items(): ### >>> mytable.items() [((0, 1), 3.1415), ((0, 0), 42), ((1, 0), 2.718), ((1, 1), 1.61)] ### Dictionaries are a very good data structure; there's some more information on them here: http://www.python.org/doc/current/tut/node7.html#SECTION007400000000000000000 Hope this helps! From dyoo@hkn.eecs.berkeley.edu Tue May 1 02:42:25 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 30 Apr 2001 18:42:25 -0700 (PDT) Subject: [Tutor] Having Python figure out whether a set is a group In-Reply-To: Message-ID: On Mon, 30 Apr 2001, Julieta Rangel wrote: > Given the following table, how can I make the computer verify whether the > following set is a group or not? The set is G = {e,a,b,ab) > The table under the binary operation * with the elements of the set looks > like: > > *_| e a b ab > --------------------------- > e| e a b ab > a| a e ab b > b| b ab e a > ab| ab b a e > > The computer would have to check the 4 properties of groups (closure, > associativity, identity element, and inverse element). By the way, the set > G is in fact a group. It is closed under the binary operation (a * b = ab, > and ab is in G, b * ab =a and a is in G, etc), it is associative (a * (b * > ab) = (a * b) * ab; e * (a * b) = (e * a) * b, etc), it has an identity > element e (a * e = a, b * e = b, ab * e = ab, e * e = e), and every element > is an inverse of itself (Note: a*a = e, b*b = e, ab*ab = e, and e*e = e).How > could the computer check for closure? I'm assuming the computer would have > to go through the elements in the table and compare them with the original > set. How could this be done? This problem requires some thinking. Does > anyone want to help or do you know where I can go for help? Let's assume that we have this table all set up, and that it's fairly easy to look up a table element if we're given the row and column. What do we need to check closure, in the mathematical sense? We need to see that, for every pair of elements (a, b) in our table, that the entry in there is within our set G. If any of these table elements aren't in G, then there no point to check the rest: we don't have closure. Otherwise, the group must be closed. The pseudocode for this sounds like: ### a definition for closure of the set G: for all the (row, column) pairs in our binary-operator table: if the element at (row, column) is not in our set G: let's report that this G isn't a group if we haven't reported failure, then all the table elements are good, so let's report success ### The Python code that corresponds to this isn't that much different. How far have you gotten though Alan Gauld's tutorial? http://www.crosswinds.net/~agauld/ The parts that will help you express these ideas are under the topics of "Sequences" and "Branching". Good luck to you. From dyoo@hkn.eecs.berkeley.edu Tue May 1 03:12:35 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 30 Apr 2001 19:12:35 -0700 (PDT) Subject: [Tutor] deciphering code In-Reply-To: Message-ID: On Mon, 30 Apr 2001, Julieta Rangel wrote: > Can anyone help me decipher the following code? I know it is to create a > polynomial and calculate its derivative, but I would like to know what the > lines do, in other words, figure out the purpose for those lines. Ok, no problem. [warning: this is long, and in some excruciating detail. You asked for it. *grin*] > import string This is called an import statement. What it says is that we need some of the functionality that a module called "string" provides us. Many of the functions that Python provides have been off-loaded into packaged modules, just to keep things clean and managable for us. When we find that we need these functions, we can "import" them, and then use them. Once we import string, we can use the functions described here: http://python.org/doc/current/lib/module-string.html There's a somewhat overwhelming list of modules here: http://python.org/doc/current/lib/lib.html but you don't need to know about all of them. The most useful ones, I've found, are: sys --- working with system resources string --- string manipulation re --- more complicated and powerful string manipulation but that's just because I do a lot of string manipulation. As you learn Python, you'll start to get familiar with the modules that you reach for. > class Poly: We're defining a class, a description that tells Python what we mean when we say "Poly". The rest of these lines explain the operations that polynomials can do. For example: > def __init__ ( self, v = 'x', c = [0]): corresponds to initializing a new Poly, and > def __str__ (self): tells Python what to do if we ever want to "print" a Poly to the user. ("str" stands for "string"ing). The double underscores are part of the name. ### Let's look at one of the definitions in a Poly: > def __init__ ( self, v = 'x', c = [0]): > """__init__(): > Initializes a polynomial > Default variable is x > Default polynomial is zero""" > self.var = v > self.coef = c > self.deg = len(c)-1 The first line: > def __init__ ( self, v = 'x', c = [0]): says that when we're trying to make a Poly, we're given the option of feeding in a 'v' ("variable"), and "c" (coefficient list). The programmer has chosen to give "defaults" to these variables: if the user doesn't tell us what the variable name or the coefficents are, then it will choose "x" and [0] by default. The next couple of lines: > """__init__(): > Initializes a polynomial > Default variable is x > Default polynomial is zero""" are just a description of what the procedure does: it's meant for people to read. This is called a documentation string, or more tersely, a "docstring". Docstrings are optional when we're defining a function. > self.var = v > self.coef = c > self.deg = len(c)-1 In order for a polynomial to keep an identity that's distinct from other Poly's, it needs to know what variable, coefficient, and degree it contains. These assignment lines store this information into it"self". Later on, we can lookup this information by asking for "self.var" or "self.coef", and in fact, we do so in the next definition: > def __str__ (self): > """__str__(): > Converts a polynomial into a string""" > x = `self.coef[0]` > for i in range (1, self.deg+1): > x = x + " + " + `self.coef[i]` + self.var + "^" + `i` > return x When we're defining __str__, we're telling Python what a "string" representation of a Polynomial would be. Without this function, Python has no idea what it should print out. Let's look at a few of the lines: > x = `self.coef[0]` This says: "Let's define the name 'x' to have the string representation of self.coef[0]." self.coef, as we remember, was the coefficient list, so self.coef[0] is looking up the first element in the list. Those backquotes are intentional: they tell Python that we want a string, not just a number. Python keeps track of the "type" of something: like mathematics, it's a label that helps us know what kind of operations are valid, and how these operations work. For example: ### >>> 5 + 4 9 >>> "5" + "4" '54' ### return different values because the "addition" operation really does depend on what we're working with. Let's look at a few more lines: > for i in range (1, self.deg+1): > x = x + " + " + `self.coef[i]` + self.var + "^" + `i` What this says is that we'd like to look at every element within the range[1, self.deg+1]. That is, for each element within such a list, we'll be doing whatever's in the "body" of this loop. Here's the body: > x = x + " + " + `self.coef[i]` + self.var + "^" + `i` Within the body, 'i' will take the value of the elements within range(1, self.deg+1). The idea is that as we're going through the loop, we slowly build up a string that represents what the polynomial looks like. Here's an example of using for loops: ### >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> for x in range(0, 10): ... print x, x**2, x**3 ... 0 0 0 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 ### range() itself is a utility function that can build lists of consecutive integers conveniently. The last line: > return x says that the return value --- what we want the function to give back --- should be this string x. Whew! From sheila@thinkspot.net Tue May 1 04:58:16 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 30 Apr 2001 20:58:16 -0700 Subject: [Tutor] Having Python figure out whether a set is a group In-Reply-To: References: Message-ID: <332C878579E@kserver.org> On Mon, 30 Apr 2001 19:43:38 -0500, "Julieta Rangel" wrote about [Tutor] Having Python figure out whether a set is a group: :Given the following table, how can I make the computer verify whether the :following set is a group or not? The set is G = {e,a,b,ab) :The table under the binary operation * with the elements of the set looks :like: : : *_| e a b ab : --------------------------- : e| e a b ab : a| a e ab b : b| b ab e a : ab| ab b a e : :The computer would have to check the 4 properties of groups (closure, :associativity, identity element, and inverse element). By the way, the set :G is in fact a group. It is closed under the binary operation (a * b = ab, :and ab is in G, b * ab =a and a is in G, etc), it is associative (a * (b * :ab) = (a * b) * ab; e * (a * b) = (e * a) * b, etc), it has an identity :element e (a * e = a, b * e = b, ab * e = ab, e * e = e), and every element :is an inverse of itself (Note: a*a = e, b*b = e, ab*ab = e, and e*e = e).How :could the computer check for closure? I'm assuming the computer would have :to go through the elements in the table and compare them with the original :set. How could this be done? This problem requires some thinking. Does :anyone want to help or do you know where I can go for help? How about storing your table as a dictionary? Here is a partial idea: >>> e='e' >>> a='a' >>> b='b' >>> ab='ab' >>> table ={} >>> table[(e,e)]=e >>> table[(e,a)]=a >>> table[(e,b)]=b >>> print table {('e', 'e'): 'e', ('e', 'b'): 'b', ('e', 'a'): 'a'} >>> To check for closure, have a list of the set values. I constructed a list from the table (after I finished entering all the values for the table) as follows: >>> set = [] >>> for elt in table.keys(): ... if elt[0] not in set: ... set.append(elt[0]) ... >>> print set ['a', 'ab', 'b', 'e'] >>> Now, to check for closure, just test to see whether each item in tables.values() is in the set. If not, then it is not closed. To check for associativity, for example, find the value of (a,b) and then take that value (which we know is ab) and cross it with another element (let's say, e) and see if (ab, e) is equivalent to a crossed with the result of (b, e) To test for an identity element, you could check whether there is an item in the set, where (item, whatever) == whatever, for each whatever in the set, and also check whether (whatever, item) == whatever. And, to check for inverses...once you've confirmed the existence of an identity element, check for each element in the set, whether there is a pair such that (element, something) == identity element. Actually, I think I really like this idea of storing the table off as a dictionary. The table really is a function (mathematically speaking), which is a mapping, which is what a dictionary represents. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From julieta_rangel@hotmail.com Tue May 1 05:52:08 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Mon, 30 Apr 2001 23:52:08 -0500 Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table in GUI Message-ID: Thanks for your suggestions. I have a question. Is it possible to have the user enter the table's contents in GUI format; that is, set up a really nice table in which the user can move freely up and down and across and enter the table's contents, and at the same time store all of the table's input into a dictionary like you suggested? >From: Sheila King >To: "Julieta Rangel" >CC: tutor@python.org >Subject: Re: [Tutor] Having Python figure out whether a set is a group >Date: Mon, 30 Apr 2001 20:58:16 -0700 > >On Mon, 30 Apr 2001 19:43:38 -0500, "Julieta Rangel" > wrote about [Tutor] Having Python figure out >whether a set is a group: > >:Given the following table, how can I make the computer verify whether the >:following set is a group or not? The set is G = {e,a,b,ab) >:The table under the binary operation * with the elements of the set looks >:like: >: >: *_| e a b ab >: --------------------------- >: e| e a b ab >: a| a e ab b >: b| b ab e a >: ab| ab b a e >: >:The computer would have to check the 4 properties of groups (closure, >:associativity, identity element, and inverse element). By the way, the >set >:G is in fact a group. It is closed under the binary operation (a * b = ab, >:and ab is in G, b * ab =a and a is in G, etc), it is associative (a * (b * >:ab) = (a * b) * ab; e * (a * b) = (e * a) * b, etc), it has an identity >:element e (a * e = a, b * e = b, ab * e = ab, e * e = e), and every >element >:is an inverse of itself (Note: a*a = e, b*b = e, ab*ab = e, and e*e = >e).How >:could the computer check for closure? I'm assuming the computer would >have >:to go through the elements in the table and compare them with the original >:set. How could this be done? This problem requires some thinking. Does >:anyone want to help or do you know where I can go for help? > >How about storing your table as a dictionary? Here is a partial idea: > > >>> e='e' > >>> a='a' > >>> b='b' > >>> ab='ab' > >>> table ={} > >>> table[(e,e)]=e > >>> table[(e,a)]=a > >>> table[(e,b)]=b > >>> print table >{('e', 'e'): 'e', ('e', 'b'): 'b', ('e', 'a'): 'a'} > >>> > >To check for closure, have a list of the set values. I constructed a list >from >the table (after I finished entering all the values for the table) as >follows: > > >>> set = [] > >>> for elt in table.keys(): >... if elt[0] not in set: >... set.append(elt[0]) >... > >>> print set >['a', 'ab', 'b', 'e'] > >>> > >Now, to check for closure, just test to see whether each item in >tables.values() is in the set. If not, then it is not closed. > >To check for associativity, for example, >find the value of (a,b) and then take that value (which we know is ab) and >cross it with another element (let's say, e) and see if (ab, e) is >equivalent >to >a crossed with the result of (b, e) > >To test for an identity element, you could check whether there is an item >in >the set, where (item, whatever) == whatever, for each whatever in the set, >and >also check whether (whatever, item) == whatever. > >And, to check for inverses...once you've confirmed the existence of an >identity element, check for each element in the set, whether there is a >pair >such that (element, something) == identity element. > >Actually, I think I really like this idea of storing the table off as a >dictionary. The table really is a function (mathematically speaking), which >is >a mapping, which is what a dictionary represents. > >-- >Sheila King >http://www.thinkspot.net/sheila/ >http://www.k12groups.org/ > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From sheila@thinkspot.net Tue May 1 05:54:38 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 30 Apr 2001 21:54:38 -0700 Subject: [Tutor] Having Python figure out whether a set is a group In-Reply-To: <332C878579E@kserver.org> References: <332C878579E@kserver.org> Message-ID: <35DBF741486@kserver.org> On Mon, 30 Apr 2001 20:58:16 -0700, Sheila King wrote about Re: [Tutor] Having Python figure out whether a set is a group: :To check for associativity, for example, :find the value of (a,b) and then take that value (which we know is ab) and :cross it with another element (let's say, e) and see if (ab, e) is equivalent :to :a crossed with the result of (b, e) I was thinking about this a bit more. I guess you could do this: if ( table[(table[(a,b)],e)] == table[(a, table[(b,e)])] ): whatever happens if associativity holds -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sheila@thinkspot.net Tue May 1 05:58:24 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 30 Apr 2001 21:58:24 -0700 Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table in GUI In-Reply-To: References: Message-ID: <36144533ABE@kserver.org> On Mon, 30 Apr 2001 23:52:08 -0500, "Julieta Rangel" wrote about Re: [Tutor]-Python figuring out groups--setting up a table in GUI: :Thanks for your suggestions. I have a question. Is it possible to have the :user enter the table's contents in GUI format; that is, set up a really nice :table in which the user can move freely up and down and across and enter the :table's contents, and at the same time store all of the table's input into a :dictionary like you suggested? Yes, but I would learn how to do it at the command line first and move on to GUI programming after a bit. (I don't even know GUI programming yet, really, and I've been teaching programming for a couple of years now--C++. I mean, I could do Visual Basic or C++ Builder, but there isn't anything like that, quite yet, for Python.) -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sale_profil@gmx.co.uk Tue May 1 09:09:21 2001 From: sale_profil@gmx.co.uk (Sergey) Date: Tue, 1 May 2001 01:09:21 -0700 (PDT) Subject: [Tutor] PROFIL DLA GKL Message-ID: <200105010809.f4189La75476@addr21.addr.com> PEhUTUw+PEhFQUQ+PFRJVExFPjwvVElUTEU+PC9IRUFEPjxCT0RZPjxQUkU+DQrP8O706Ov8 IOTr/yDDyssuICAgPGEgaHJlZj0iaHR0cDovL3Byb2ZpbHkuYWRkci5jb20iPmh0dHA6Ly9w cm9maWx5LmFkZHIuY29tPC9hPg0KDQrP8OXk6+Dj4P4g8e4g8err4OTgIOIgzO7x6uLlICju 8uPw8+fq4CDq7u3y5ent5fDgLCDk7vHy4OLq4CDgL/IpOg0KCQkJCQkJDQrP8O706Ov8IM/R LTIgKDUw9TUwIOzsKQkJNDgg7C7vLu/g9+rgCTE0LDAwIPDz4S/sLu8uDQrP8O706Ov8IM/N LTIgKDUw9TQwIOzsKQkJNDgg7C7vLu/g9+rgCTExLDYwIPDz4S/sLu8uDQrP8O706Ov8IM/R LTQgKDc19TUwIOzsKSAJMzYg7C7vLu/g9+rgCTE2LDQwIPDz4S/sLu8uDQrP8O706Ov8IM/N LTQgKDc19TQwIOzsKSAJMzYg7C7vLu/g9+rgCTE0LDMwIPDz4S/sLu8uDQrP8O706Ov8IM/P ICggNjD1Mjfs7CkgCQk0OCDsLu8u7+D36uAJMTAsODAg8PPhL+wu7y4NCs/w7vTo6/wgz80g KDI49TI3IOzsKQkJODQg7C7vLu/g9+rgCTcsNjAgIPDz4S/sLu8uDQrT4+7r7uog5+D56PLt ++kg7+Xw9C4JCTMwIOwu7y7v4Pfq4Ak2LDQwICDw8+Ev7C7vLiANCg0KzvLk5evq4C4NCsrw 4PHq4CD04PHg5O3g/yDr4PLl6vHt4P8gKyDq7uvl8O7i4O3o5Swg4/Dz7fLu4urgIODq8Ojr 7uLg/yANClRpZWZncnVkIExGIEQxNCwg4u7k7uTo8e/l8PHo7u3t++Ug6vDg8eroIOTr/yDi 7fPy8OXt7ej1IPDg4e7yIA0KKyDq7uvl8O7i4O3o5Swg6uvl6CDk6/8g7+vo8uroLCDx8ujw 7u/u8OAuDQoozu/y7uL75SDx6ujk6uggKyDk6Ovl8PHq6Okg5O7j7uLu8CDxIO/w7ujn4u7k 6PLl6+XsKQ0KDQrU4O3l8OAg0O7x8ejp8eru4+4g7/Du6Ofi7uTx8uLgICju7/IgKyDw7uft 6PbgKS4NCg0Kyujx8ugg7ODr//Dt++Ug7/Du9OXx8eju7eDr/O375SDoIOH78u7i++UgKPLu 6/zq7iDu7/Lu7CAtIO3o5uUg9uXtIO3l8iEpDQoNCs/u5PDu5+Xy7ejqICj96+Xq8vDu8/Hy 4O3u4u737eD/IOru8O7h6uApIA0K5Ov/IOHl8u7t4Cwg5Ov/IOPo7/Hu6uDw8u7t4CAyLzMg 8PPhLi/48i4NCg0K8uXrLiAwOTUgOTcwLTA4LTc4DQoNCjwvUFJFPjwvYm9keT48L2h0bWw+ DQoNCg== From wheelege@tsn.cc Tue May 1 10:12:18 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Tue, 1 May 2001 19:12:18 +1000 Subject: [Tutor] Program not accessing while loops References: Message-ID: <010301c0d21e$d3308c80$0200a8c0@ACE> This is a multi-part message in MIME format. ------=_NextPart_000_0100_01C0D272.A3F1A040 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable mainmen =3D raw_input(">") while mainmen =3D=3D 1: Your getting a string here, and not an integer. So, 'while mainmen = =3D=3D 1' will never, ever be true. Ever. So, what you want is to convert it to an integer...with something like = :- mainmen =3D int(raw_input(">")) To account for something other than an integer, and to make sure it = doesn't crash when the user writes something like 'go away!', wrap it in = a try-except block. try: mainmen =3D int(raw_input(">")) except: print 'Please enter an integer' Hope that helped, Glen. ------=_NextPart_000_0100_01C0D272.A3F1A040 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
<snip snip snip>
   =20 mainmen =3D raw_input(">")
    while mainmen =3D=3D = 1:

<snip snip snip>
 
  Your getting a string here, and not an integer.  So, = 'while=20 mainmen =3D=3D 1' will never, ever be true.  Ever.
  So, what you want is to convert it to an integer...with = something=20 like :-
 
  mainmen =3D int(raw_input(">"))
 
  To account for something other than an integer, and to make = sure it=20 doesn't crash when the user writes something like 'go away!', wrap it in = a=20 try-except block.
 
  try:
      mainmen =3D = int(raw_input(">"))
  except:
      print 'Please enter an = integer'
 
  Hope that helped,
  Glen.
------=_NextPart_000_0100_01C0D272.A3F1A040-- From alan.gauld@bt.com Tue May 1 10:06:11 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 1 May 2001 10:06:11 +0100 Subject: [Tutor] deciphering code Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D72C@mbtlipnt02.btlabs.bt.co.uk> > Can anyone help me decipher the following code? Nope, not me - too lazy! But it seems that several of your questions are answered (in Scheme) in the book "Structure and Interpretation of Computer Programs" by Abelman and Sussman(s). It might be useful to find a copy (in a local college library maybe?) Specifically chapter two covers symbolic algebra including addition, multiplication and derivation of polynomials... Alan G. From alan.gauld@bt.com Tue May 1 10:30:07 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 1 May 2001 10:30:07 +0100 Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table in GUI Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D72F@mbtlipnt02.btlabs.bt.co.uk> > I mean, I could do Visual Basic or C++ Builder, but there isn't > anything like that, quite yet, for Python.) We're not too far off: Glade - for GTk? Blackadder - for Qt? SpecTcl (with SpecPython addin) - for Tkinter(*) I think I've seen a wxPython one somewhere too? And Kdeveloper might handle Python too - I can't remember... They don't have all the bells and whistles of VB or Delphi yet but they do all build a GUI visually. Alan G (*)SpecTcl is no longer supported so the Tkinter code it generates uses a depricated style of widget configuration - but it's very easy to convert, in fact If I was lazy & determined enough I'd write a script :-) From alan.gauld@bt.com Tue May 1 10:36:09 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 1 May 2001 10:36:09 +0100 Subject: [Tutor] Program not accessing while loops Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D730@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0D222.26EA8A80 Content-type: text/plain; charset="iso-8859-1" keep running and asking for input, but it won't call on the loop. mainmen = raw_input(">") while mainmen == 1: raw_input returns a string, you are testing for a number. You need to convert mainmen to an int: mainmen= int(mainmen) OR you need to test for a string: while mainmen n== "1" BUT do you really want a while loop here? It will loop forever printing print "This function is under construction" Surely an if statement would be sufficient? Specifically an if/elif set: if mainmenu == 1: print... elif mainmenu == 2: print... elif mainmenu == 3: # do the exit stuff here just a thought, Alan G. ------_=_NextPart_001_01C0D222.26EA8A80 Content-type: text/html; charset="iso-8859-1"
keep running and asking for input, but it won't call on the loop.
 
    mainmen = raw_input(">")
    while mainmen == 1:
 
raw_input returns a string, you are testing for a number.
You need to convert mainmen to an int:
 
mainmen= int(mainmen)
 
OR you need to test for a string:
 
while mainmen n== "1"
 
BUT do you really want a while loop here?
It will loop forever printing
 
         print "This function is under construction"
Surely an if statement would be sufficient?
 
Specifically an if/elif set:
 
if mainmenu == 1: print...
elif mainmenu == 2: print...
elif mainmenu == 3:
   # do the exit stuff here
 
just a thought,
 
Alan G.
------_=_NextPart_001_01C0D222.26EA8A80-- From sheila@thinkspot.net Tue May 1 12:30:31 2001 From: sheila@thinkspot.net (Sheila King) Date: Tue, 01 May 2001 04:30:31 -0700 Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table in GUI In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D72F@mbtlipnt02.btlabs.bt.co.uk> References: <5104D4DBC598D211B5FE0000F8FE7EB20751D72F@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <4C506775CBB@kserver.org> On Tue, 1 May 2001 10:30:07 +0100, alan.gauld@bt.com wrote about RE: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table in GUI: :> I mean, I could do Visual Basic or C++ Builder, but there isn't :> anything like that, quite yet, for Python.) : :We're not too far off: That's why I said "quite yet". My understanding, is that they are all alpha/beta quality. I wouldn't recommend them to a newbie who's just starting out learning GUI. They would have a devil of a time figuring out what were their own coding mistakes, and what were bugs in the RAD software they were using. : :Glade - for GTk? :Blackadder - for Qt? :SpecTcl (with SpecPython addin) - for Tkinter(*) : :I think I've seen a wxPython one somewhere too? Boa Constructor? :And Kdeveloper might handle Python too - I can't remember... : :They don't have all the bells and whistles of VB or Delphi :yet but they do all build a GUI visually. But, like I said above, they are buggy at this time, right? Not "release quality" software? Or, am I mistaken? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From bill_tolbert@bigfoot.com Tue May 1 13:49:15 2001 From: bill_tolbert@bigfoot.com (Bill Tolbert) Date: Tue, 1 May 2001 08:49:15 -0400 (EDT) Subject: [Tutor] Need a file browser dialog Message-ID: Hi folks. First, a quick note of thanks for the kind help you guys provide. This tutor list is great. I've looked in the usual places and can't find anything that allows me to do a File/open operation in Tkinter and get a file browse dialog. I noticed that this is an open question on python.faqts.com in the Tkinter folder. I promise to give an answer when I get it straight myself! Thanks, Bill From alan.gauld@bt.com Tue May 1 12:33:56 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 1 May 2001 12:33:56 +0100 Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table in GUI Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D736@mbtlipnt02.btlabs.bt.co.uk> > That's why I said "quite yet". My understanding, is that they are all > alpha/beta quality. I wouldn't recommend them to a newbie > who's just starting out learning GUI. I've only used SpecTCL but it is product quality - it was commercial for a short while. Its never died on me yet but the code it produces is a little idiosyncratic. But once you get used to it its certainly workable for complex GUIs. (And it will generate Perl, Tcl and Java code too...) As for Blackadder it is a commercial product but I don't know how useful the GUI builder support is. (I'm not even 100% sure it has any!) > They would have a devil of a time figuring > out what were their own coding mistakes, I suspect just figuring out what the code is supposed to be doing is the tricky bit. Thats why learningh to craft it by hand first is a good idea - I found that true of C++/MFC in Windows too FWIW. VB is the only GUI builder where you really don't need to know anyting about the code produced - which is just as well IMHO! > :I think I've seen a wxPython one somewhere too? > Boa Constructor? Thats the one :-) > Not "release quality" software? Or, am I mistaken? SpecTcl and BlackAdder are both release quality but the former is getting a bit too old. As for the others, I've heard good reports of Glade even though it is still officially beta(or even alpha?). Alan g. From rick@niof.net Tue May 1 14:02:24 2001 From: rick@niof.net (Rick Pasotto) Date: Tue, 1 May 2001 09:02:24 -0400 Subject: [Tutor] Need a file browser dialog In-Reply-To: ; from bill_tolbert@bigfoot.com on Tue, May 01, 2001 at 08:49:15AM -0400 References: Message-ID: <20010501090224.D23289@tc.niof.net> On Tue, May 01, 2001 at 08:49:15AM -0400, Bill Tolbert wrote: > Hi folks. First, a quick note of thanks for the kind help you guys > provide. This tutor list is great. > > I've looked in the usual places and can't find anything that allows me to > do a File/open operation in Tkinter and get a file browse dialog. I > noticed that this is an open question on python.faqts.com in the Tkinter > folder. I promise to give an answer when I get it straight myself! I asked this some time ago and never got a response. After writing my own I discovered that it was there all the time, right under your nose, just kinda hidden: >>> from FileDialog import FileDialog >>> print FileDialog.__doc__ Standard file selection dialog -- no checks on selected file. Usage: d = FileDialog(master) file = d.go(dir_or_file, pattern, default, key) if file is None: ...canceled... else: ...open file... All arguments to go() are optional. The 'key' argument specifies a key in the global dictionary 'dialogstates', which keeps track of the values for the directory and pattern arguments, overriding the values passed in (it does not keep track of the default argument!). If no key is specified, the dialog keeps no memory of previous state. Note that memory is kept even when the dialog is cancelled. (All this emulates the behavior of the Macintosh file selection dialogs.) >>> -- "FIJA is not a double-edged sword --- it is a shield against the sword of government." --- Tom Glass Rick Pasotto email: rickp@telocity.com From lsloan@umich.edu Tue May 1 14:09:01 2001 From: lsloan@umich.edu (Lance E Sloan) Date: Tue, 01 May 2001 09:09:01 -0400 Subject: [Tutor] FieldStorage solution summary Message-ID: <200105011309.JAA17875@birds.us.itd.umich.edu> I want to say thanks to Daniel Yoo and others (sorry, I seem to have misplaced some of the messages I received) for answering my questions about converting a FieldStorage object into a dictionary. I think the best way I could thank them and help others is to contribute the solution to my problem back to the list. The problem was that I'm using FieldStorage objects from the cgi module and the DocumentTemplate module (pried out of Zope) to write some CGIs. The DocumentTemplate functions can use a dictionary to fill in blanks in the templates by name. In many cases, I wanted the CGIs to print what the user had just submitted, which is in a FieldStorage object and that's not quite like a dictionary. Sometimes I might also have one or more other dictionaries with values that I want printed along with the values from FieldStorage. With the suggestions I had gotten about converting FieldStorage to a dictionary, I came up with this function, dictcat, that will take any number of dictionaries or FieldStorage objects and concatenate them into a single dictionary. When you run this as-is, it will print out the results of the examples: import cgi def dictcat(*dicts): """ Concatenate any number of dictionary or FieldStorage objects together, ignoring non-dictionaries. If the objects have conflicting keys, the last one wins. If a FieldStorage object has multiple values for a key, they are stored in the resulting dictionary as a list. """ if len(dicts) == 0: return(None) all = {} for d in dicts: if (isinstance(d, cgi.FieldStorage)): for k in d.keys(): # use getvalue here in case multiple fields with same name all[k] = d.getvalue(k) if (type(d) == type({})): all.update(d) if (all == {}): return(None) else: return(all) # Examples... if (__name__ == '__main__'): import os x = {'a': 'xa', 'b': 'xb'} y = {'a': 'ya', 'c': 'yc', 'd': 'yd'} print x print y # order matters when there are duplicate keys # the last one wins print dictcat(x, y) print dictcat(y, x) # more than two are allowed print dictcat(vars(), x, y) # non-dictionaries are ignored print dictcat(x, 5) print dictcat(y, dir()) print dictcat('lsloan', 10) # an empty argument list is handled gracefully, too print dictcat() # simulate some CGI input os.environ['QUERY_STRING'] = 'years=5&name=George&name=Jerry' f = cgi.FieldStorage() print f print dictcat(f, x) Hope this helps other Python newbies. I would also appreciate critiques/suggestions from Python experts if they think I should be doing this differently or if they know a better way. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Perl & Python CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From virketis@fas.harvard.edu Tue May 1 15:17:57 2001 From: virketis@fas.harvard.edu (Pijus Virketis) Date: Tue, 01 May 2001 10:17:57 -0400 Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table in GUI Message-ID: <200105011413.KAA11625@smtp3.fas.harvard.edu> Hi Julieta, well, I don't have the knowledge of some of the gurus on this list, but here goes ... >Is it possible to have the >user enter the table's contents in GUI format; that is, set up a really nice >table in which the user can move freely up and down and across and enter the >table's contents, and at the same time store all of the table's input into a >dictionary like you suggested? I have been grappling with a python module called Tkinter (, a good tutorial an overview at http://www.pythonware.com/library/tkinter/introduction/ by Fredrik Lundh), which produces GUIs. In principle, your table entry frame would just be a combination of Entry widgets and Label widgets. Entry widgets let you enter information, and Labels would just display the margins of the table. To achieve the right placement, you can use the convenient grid() method, which lets you array your GUI widgets in a matrix on the frame. You can move among the cells with a Tab and mouse, but I am sure keyboard control can be somehow implemented. As for storing the input, python interacts with Tk via StringVar() objects. You set some variable to a stringvar and then Entry widgets can access it to enter information, and python can access it to retrieve it. Storing them all in a dictionary would just be a question of storing a bunch of strings in a dictionary: straightforward. I hope this helps, Pijus ---------------------------------------------------------------------------- ------------------- Please have a look at my weblog at www.fas.harvard.edu/~virketis. From britt_green@hotmail.com Tue May 1 17:27:10 2001 From: britt_green@hotmail.com (Britt Green) Date: Tue, 01 May 2001 09:27:10 -0700 Subject: [Tutor] SSH Client? Message-ID: Might anyone know if there is an SSH client written in python anywhere? _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From deirdre@deirdre.net Tue May 1 17:40:43 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Tue, 1 May 2001 09:40:43 -0700 Subject: [Tutor] SSH Client? In-Reply-To: References: Message-ID: >Might anyone know if there is an SSH client written in python anywhere? I don't know of one. -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From sales@naisnet.com Tue May 1 17:45:54 2001 From: sales@naisnet.com (North Atlantic Information Systems) Date: Tue, 01 May 2001 12:45:54 -0400 Subject: [Tutor] Components Price List - May 2001 Message-ID: North Atlantic Information Systems Price List
NAIS

North Atlantic Information Systems
One Colonie Street
Albany, New York 12207
Phone (518) 434-0493
Fax (518) 434-0925
Email
sales@naisnet.com
http://www.albanycomputers.com
 


Email Price List May 2001

Pentium III Processors
Intel Pentium III 677EB (FC-PGA) $153.95
Intel Pentium III 650E (FC-PGA) $176.95
Intel Pentium III 700E (FC-PGA) $188.95
Intel Pentium III 733EB (FC-PGA) $213.95
Intel Pentium III 800E (FC-PGA) $220.95
Intel Pentium III 800EB (FC-PGA) $220.95
Intel Pentium III 850E (FC-PGA) $236.95
Intel Pentium III 866EB (FC-PGA) $257.95
Intel Pentium III 933EB (FC-PGA) $308.95
Intel Pentium III 1000EB (FC-PGA) $382.95
Celeron Processors
Intel Celeron 566mhz $81.95
Intel Celeron 633mhz $87.95
Intel Celeron 600mhz $88.95
Intel Celeron 677mhz $102.95
Intel Celeron 700mhz $110.95
AMD Processors
AMD Duron Socket 650 SOC $70.95
AMD Duron Socket 700 SOC $70.95
AMD Althon Socket K7 750 $104.95
AMD Duron Socket 800 SOC $106.95
AMD Althon Slot A K7 700 $110.95
AMD Althon Slot A K7 750 $110.95
AMD Althon Slot A K7 800 $136.95
AMD Althon Socket K7 850 $137.95
AMD Althon Socket K7 900 $174.95
AMD Althon Socket K7 1000 $245.95
AMD Althon Socket K7 1100 $296.95
IDE Drives
< TR>
Fujitsu 10.2gb ATA/66 7200rpm $129.95
Fujitsu 10.2gb ATA/100 5400rpm $121.95
Fujitsu 10.2gb ATA/100 7200rpm $129.95
Fujitsu 10.2gb ATA/66 5400rpm $121.95
Fujitsu 20.4gb ATA/100 5400rpm $134.95
Fujitsu 20.4gb ATA/100 7200rpm $160.95
Fujitsu 20.4gb ATA/66 5400rpm $136.95
Fujitsu 30.7gb ATA100 5400rpm $153.95
Fujitsu 40.9gb ATA100 5400rpm $189.95
IBM 15gb ATA/100 7200rpm $149.95
IBM 20gb ATA/100 5400rpm $149.95
IBM 30gb ATA/100 7200rpm $195.95
IBM 45gb ATA/100 7200rpm $208.95
IBM 65gb ATA/100 7200rpm $318.95
IBM 75gb ATA/100 7200rpm $435.95
Memory
32mb SDRAM DIMM PC100 $18.95
64mb SDRAM DIMM PC100 $30.95
64mb SDRAM DIMM PC133 $30.95
128mb SDRAM DIMM PC100 $56.95
128mb SDRAM DIMM PC133 $56.95
256mb SDRAM DIMM PC100 $108.95
256mb SDRAM DIMM PC133 $108.95
Motherboards
Abit BE6 II Pentium III Motherboard (Slot 1) $153.95
Abit BX133 RAID Pentium III Motherboard (Socket 370) $153.95
Abit KT7 Athlon/Duron Motherboard (Socket A) $170.95
Abit KT7A Athlon/Duron Motherboard (Socket A) $182.95
Abit KT7A-RAID Athlon/Duron Motherboard (Socket A) $201.95
Abit KT7-RAID Athlon/Duron Motherboard (Socket A) $195.95
Abit SA6R Pentium III Motherboard (Socket 370) $193.95
Abit SE6 Pentium II/III Motherboard (Socket 370) $167.95
Abit VH6 II Pentium III Motherboard (Socket 370) $127.95
Ab it VH6 Pentium III Motherboard (Socket 370) $122.95
Abit VL6 Pentium III Motherboard (Socket 370) $105.95
Abit VP6 Pentium III Motherboard (Socket 370) $196.95
Network
3com 3CR990TX95 10/100 Network Card $116.95
3com OfficeConnect 10/100 16 Port Hub $258.95
Patch Cable - 10 Foot $4.95
Patch Cable - 14 Foot $5.95
Patch Cable - 25 Foot $9.95
Patch Cable - 3 Foot $2.95
Patch Cable - 50 Foot $14.95
Patch Cable - 7 Foot $3.95
WiseCom 10/100 16 Port Hub $188.95
WiseCom 10/100 8 Port Hub $71.95
WiseCom 10/100 PCI Network Card $14.95
WiseCom 8 Port 10baseT Hub $26.95
Keyboards
Logitech Dexxa 107Key Keyboard PS/2 $11.95
Logitech Dexxa Internet Keyboard PS/2 $22.95
Microsoft Natural Keyboard Elite $40.95
Microsoft Natural Keyboard Pro $72.95
Mice
Logitech Dexxa 2BTN PS/2 w/ser adpt Mouse $3.95
Logitech Dexxa 2BTN Wheel Mouse PS/2 $7.95
Logitech Dexxa Optical Mouse PS/2 $25.95
Microsoft 062-00003 Wheel Mouse $19.95
Microsoft D58-00002 Intellimouse Optical $56.95

BookPC Image Build your own Pentium III Book PC

Build Your Own System Online!

Our Email price list is never sent unsolicited, and is available by subscription only.  If you have received this price list in error and wish
to be removed, simply go to http://www.naisnet.com/newsletter/remove.asp  
 

From cwebster@nevada.edu Tue May 1 18:17:37 2001 From: cwebster@nevada.edu (Corran Webster) Date: Tue, 1 May 2001 10:17:37 -0700 Subject: [Tutor] determining whether a set is a group In-Reply-To: <3AEC3A7E.1868590F@seatech.fau.edu> References: <3AEC3A7E.1868590F@seatech.fau.edu> Message-ID: >Daniel Yoo wrote: > >> On Sat, 28 Apr 2001, Sheila King wrote: >> >> > The axioms (basic rules) for a group are: >> > ( where the dot (•) symbolizes some operation...) >> > >> > 1.CLOSURE: If a and b are in the group then a • b is also in the group. >> > 2.ASSOCIATIVITY: If a, b and c are in the group then (a • b) >>• c = a • (b • >> > c). >> > 3.IDENTITY: There is an element e of the group such that for >>any element a >> > of the group >> > a • e = e • a = a. >> > 4.INVERSES: For any element a of the group there is an >>element a^(-1) such >> > that >> > a • a^(-1) = e >> > and >> > a^(-1) • a = e >> > >The pb is that my computer can't handle very well infinite sets... how does a >program like Mapple handle this kind of things ? Programs like Mathematica and Maple handle infinite sets either by approximation (eg. for real numbers) or by dealing with a finite subset and hoping it doesn't get too big. This is much the same as the way that python handles the potentially infinite, with floating point numbers and long integers. Indeed it's universal for all computers without unlimited memory ;) Programs and routines in Maple for dealing with infinite groups almost certainly assume that the operations that you supply are valid group operations. >How can i implement something whose cardinal is Cantor something >(ie. infinite) ? In Python you could go a long way by defining a class to represent the elements of the set and using the __mul__, __div__ etc. special methods to implement the group operations. This would allow you to work with a finite number of elements at a time, but taken from an infinite group. You couldn't solve Julieta's problem for an infinite group using this sort of thing, however. As far as I can see, the best solution to the original problem (given a finite set and the Cayley matrix of an operation on the set, is it a group?) is a brute force checking of the axioms. For efficiency it's probably best use a dictionary to represent the matrix, rather than a list of lists, and for generality it's probably better to have the algortihm work with the operation as a function, rather than directly with the matrix, but I could be wrong. Eg. (untested code) def cayleyToOp(set, cayley): """Given a set and a Cayley matrix, returns a function which performs the operation on two elements.""" matrix = {} for a in range(len(set)): for b in range(len(set)): matrix[(set[a], set[b])] = cayley[a][b] return lambda a, b, matrix=matrix: matrix[(a,b)] Z3 = [0, 1, 2] Z3Cayley = [[0,1,2], [1,2,0], [2,0,1]] Z3op = cayleyToOp(Z3, Z3Cayley) print Z3op(1,1) #should print 2 of course Z3op could be more efficiently implimented as def Z3op(a, b): return (a+b) % 3 which is why the group checking stuff will be more flexible if you allow functions. >Although i remember what a group is , i don't remember what groups are useful >for....... any math teachers? As it so happens, I teach math at UNLV. Groups typically come up in situations where there is symmetry of some sort and so can be used to describe the symmetry which is present. Knowing symmetries can help you find and classify solutions to concrete problems. They are also one of the fundamental building blocks of abstract algebra and most interesting algebraic systems involve some sort of group structure. The standard addition of numbers is an example of a group. Regards, Corran From bdupire@seatech.fau.edu Tue May 1 20:25:55 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Tue, 01 May 2001 15:25:55 -0400 Subject: [Tutor] determining whether a set is a group References: <3AEC3A7E.1868590F@seatech.fau.edu> Message-ID: <3AEF0DC3.3152E111@seatech.fau.edu> Thank you for your answer. A few years ago, iwas only doing mathematics and physics and the kind of exercice to practice we got was like the following one: a * b = a+b - a x b is (Z, *) a group ? Yes ? no ? If no how can i modify it to make it a group ? It would be interesting to make a computer program to solve this kinds of pb. As you suggest it, i would use a subset, lets say -10 ; 10 (because 0, 1 are often worth to try as a general rule ) and additionnally i would build a function, that takes a variable and checks if it belongs to Z Answer: if b= 1, a * b = a+ b - a x b = a + 1 - a x 1 = 1 so a * 1 = 1 whatever 'a' is. so 1 has no inverse, i have to remove it from Z to have a group.... But to make a computer think like that is not so easy... :o) Benoit Corran Webster wrote: > > > As far as I can see, the best solution to the original problem (given > a finite set and the Cayley matrix of an operation on the set, is it > a group?) is a brute force checking of the axioms. For efficiency > it's probably best use a dictionary to represent the matrix, rather > than a list of lists, and for generality it's probably better to have > the algortihm work with the operation as a function, rather than > directly with the matrix, but I could be wrong. > > Eg. (untested code) > > def cayleyToOp(set, cayley): > """Given a set and a Cayley matrix, returns a function which > performs the operation on two elements.""" > matrix = {} > for a in range(len(set)): > for b in range(len(set)): > matrix[(set[a], set[b])] = cayley[a][b] > return lambda a, b, matrix=matrix: matrix[(a,b)] > > Z3 = [0, 1, 2] > Z3Cayley = [[0,1,2], [1,2,0], [2,0,1]] > Z3op = cayleyToOp(Z3, Z3Cayley) > > print Z3op(1,1) > #should print 2 > > of course Z3op could be more efficiently implimented as > > def Z3op(a, b): > return (a+b) % 3 > > which is why the group checking stuff will be more flexible if you > allow functions. > > >Although i remember what a group is , i don't remember what groups are useful > >for....... any math teachers? > > As it so happens, I teach math at UNLV. Groups typically come up in > situations where there is symmetry of some sort and so can be used to > describe the symmetry which is present. Knowing symmetries can help > you find and classify solutions to concrete problems. > > They are also one of the fundamental building blocks of abstract > algebra and most interesting algebraic systems involve some sort of > group structure. The standard addition of numbers is an example of a > group. > > Regards, > Corran > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From dyoo@hkn.eecs.berkeley.edu Wed May 2 03:17:34 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 1 May 2001 19:17:34 -0700 (PDT) Subject: [Tutor] SSH Client? In-Reply-To: Message-ID: On Tue, 1 May 2001, Britt Green wrote: > Might anyone know if there is an SSH client written in python anywhere? I couldn't find an ssh client in Python, sorry. I wonder if it would be difficult to write wrappers for the openssh stuff at: http://www.openssh.org I did find cryptography stuff here: http://www.post1.com/home/ngps/m2/ M2Crypto implements a Python wrapper for OpenSSL, but it might not be relevant with what you want. From julieta_rangel@hotmail.com Wed May 2 04:17:19 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Tue, 01 May 2001 22:17:19 -0500 Subject: [Tutor] converting unkown amount of input into strings Message-ID: I have a dumb question. I'm trying to write a program which differentiates polynomials. In this program, the user enters the degree of the polynomial, and then is asked for the coefficients of the polynomial. How can I store these coefficients into a list or into a string so that I can use them later in the following line: r = Poly (c=[]) This is what I have so far: import string class Poly: def __init__ ( self, v = 'x', c = [0]): """__init__(): Initializes a polynomial Default variable is x Default polynomial is zero""" self.var = v self.coef = c self.deg = len(c)-1 def __str__ (self): """__str__(): Converts a polynomial into a string""" x = `self.coef[0]` for i in range (1, self.deg+1): x = x + " + " + `self.coef[i]` + self.var + "^" + `i` return x def Derivative(p): """Input: an instance of a polynomial Output: a polynomial that is the derivative of the input polynomial Side Effects: None""" pv=p.var pc=[] if p.deg==0: return Poly (v=pv,c=[0]) else: for i in range(0,p.deg): d=(i+1)*p.coef[i+1] pc.append(d) return Poly (v=pv,c=pc) I want the input (the coefficients)from the following line to be stored on a string, or list so that I can use them later on (keep scrolling until you find the place where I want to insert the coefficients entered) a = input ("Enter the degree of your polynomial ") i = 1 while i<=a+1: b=a while b>=0: w = input("Enter coefficient of x^ %s." % (b) ) b=b-1 i = i + 1 r = Poly (c=[w]) # This is where I want to insert the coefficients. Once the person enters the coefficients, how can I # insert them inside the brackets. The way I have it right now the program only considers the last coefficient entered, but I want the program to calculate the derivative of the entire input p = Poly (c = [-1,1,2]) q = Poly (v = 'y', c = [-1,0,2,0,4,3]) m = Derivative(p) n = Derivative(q) o = Derivative(r) print "The derivative of %s is: \n %s" % (p,m) print " " print "The derivative of %s is: \n %s" % (q,n) print " " print "The derivative of %s is: \n %s" % (r,o) print " " Again, any help will be greatly appreciated. Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From bdupire@seatech.fau.edu Wed May 2 04:25:18 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Tue, 01 May 2001 23:25:18 -0400 Subject: [Tutor] converting unkown amount of input into strings References: Message-ID: <3AEF7E1E.FEE7CF49@seatech.fau.edu> This should do what you need... coeff is the list of coefficient coeff[0] is coeff for x^0 coeff[1] is coeff for x... etc... degree=raw_input('degree ?') coeff=[] for i in range (0, eval(degree)+1): coefficient = raw_input('coeff for x^ %i ? ' %i) coeff.append(coefficient) Julieta Rangel wrote: > I have a dumb question. I'm trying to write a program which differentiates > polynomials. In this program, the user enters the degree of the polynomial, > and then is asked for the coefficients of the polynomial. How can I store > these coefficients into a list or into a string so that I can use them later > in the following line: > > r = Poly (c=[]) > > This is what I have so far: > import string > class Poly: > def __init__ ( self, v = 'x', c = [0]): > """__init__(): > Initializes a polynomial > Default variable is x > Default polynomial is zero""" > self.var = v > self.coef = c > self.deg = len(c)-1 > def __str__ (self): > """__str__(): > Converts a polynomial into a string""" > x = `self.coef[0]` > for i in range (1, self.deg+1): > x = x + " + " + `self.coef[i]` + self.var + "^" + `i` > return x > > def Derivative(p): > """Input: an instance of a polynomial > Output: a polynomial that is the derivative of the input polynomial > Side Effects: None""" > pv=p.var > pc=[] > if p.deg==0: > return Poly (v=pv,c=[0]) > else: > for i in range(0,p.deg): > d=(i+1)*p.coef[i+1] > pc.append(d) > return Poly (v=pv,c=pc) > > I want the input (the coefficients)from the following line to be stored on a > string, or list so that I can use them later on (keep scrolling until you > find the place where I want to insert the coefficients entered) > a = input ("Enter the degree of your polynomial ") > > i = 1 > while i<=a+1: > > b=a > while b>=0: > > w = input("Enter coefficient of x^ %s." % (b) ) > b=b-1 > i = i + 1 > r = Poly (c=[w]) # This is where I want to insert the coefficients. > > Once the person enters the coefficients, how can I > # insert them inside the brackets. The way I have it right now the program > only considers the last coefficient entered, but I want the program to > calculate the derivative of the entire input > > p = Poly (c = [-1,1,2]) > q = Poly (v = 'y', c = [-1,0,2,0,4,3]) > m = Derivative(p) > n = Derivative(q) > o = Derivative(r) > print "The derivative of %s is: \n %s" % (p,m) > print " " > print "The derivative of %s is: \n %s" % (q,n) > print " " > print "The derivative of %s is: \n %s" % (r,o) > print " " > > Again, any help will be greatly appreciated. > > Julieta > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From bdupire@seatech.fau.edu Wed May 2 05:04:00 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Wed, 02 May 2001 00:04:00 -0400 Subject: [Tutor] converting unkown amount of input into strings References: Message-ID: <3AEF8730.718EE54@seatech.fau.edu> Julieta, oups... i sent my answer too quickly The debugged program is degree=input('degree ?') coeff=[] for i in range (0, degree+1): coefficient = input('coeff for x^ %i ? ' %i) coeff.append(coefficient) print coeff these are the explanations..... I saw you wanted to use 'while' to loop over the coefficients... Use 'for' instead because you know exactly the number of iterations you want to perform. If the user enters degree= 3, you know you want to perform 4 times the loop (don't forget coeff 0) --> that's degree+1! "while " is to be used when you don't know when gonna be false, and therefore don't know how many loops you want to perform. ex: while a>=1: a=input("enter a number..") You really don't know when the user will enter a number less than 1 This can loop forever ! or just once... range(0,n) is an instruction that generates a sequence [0, 1, 2, .. n-1] I loop over this sequence to get the coefficients... for i in range(0, degree+1): will affect the value 0 to i, run the loop then i=1, run the loop... so on, till i= degree you can now use your program like this myPoly = Poly('x', coeff) or myPoly = Poly(c= coeff) Poly() creates a new Poly object, and call the __init__ method with the arguments..(the first argument being a reference to the object just created). It returns your Polynome object.... benoit From julieta_rangel@hotmail.com Wed May 2 06:35:05 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Wed, 02 May 2001 00:35:05 -0500 Subject: [Tutor] integration of polynomials in Python Message-ID: I finally finished the differentiation program. What changes should I make so that instead of differentiating, my program integrates polynomials. Can anyone help? Here you have my finished program. It is not the best program you'll ever see :) but I'm very proud of it. It took me forever to put it together, eventhough I had to ask you guys for help in writing every line. Thanks a lot! :) Anyway, here you have the program. What can I do to make it integrate? import string class Poly: def __init__ ( self, v = 'x', c = [0]): """__init__(): Initializes a polynomial Default variable is x Default polynomial is zero""" self.var = v self.coef = c self.deg = len(c)-1 def __str__ (self): """__str__(): Converts a polynomial into a string""" x = `self.coef[0]` for i in range (1, self.deg+1): x = x + " + " + `self.coef[i]` + self.var + "^" + `i` return x def Derivative(p): """Input: an instance of a polynomial Output: a polynomial that is the derivative of the input polynomial Side Effects: None""" pv=p.var pc=[] if p.deg==0: return Poly (v=pv,c=[0]) else: for i in range(0,p.deg): d=(i+1) * p.coef[i+1] pc.append(d) return Poly (v=pv,c=pc) degree = input('Enter the degree of your polynomial') coef=[] for i in range (0,degree+1): coefficient = input('Enter the coefficient for x^ %i ? ' %i) coef.append(coefficient) r = Poly (c = coef) o = Derivative(r) print "The derivative of %s is: \n %s" % (r,o) print " " # This is some code to test new functions t = Integrate(p) u = Multiply(p,q) print "The intgral of %s is: \n %s" % (p,t) print " " print "The product of %s and \n %s is: \n %s" % (p,q,u) print " " Any help is truly appreciated. Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From deirdre@deirdre.net Wed May 2 07:20:42 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Tue, 1 May 2001 23:20:42 -0700 Subject: [Tutor] integration of polynomials in Python In-Reply-To: References: Message-ID: > What can I do to make it integrate? Oh geez, I had calculus in 1976. If I get it wrong, don't yell too loudly. :) A simple integral is simply the reverse of the differential. So, given the equation: 2x^2 + 4x + 3 = 0 The differential would be: 4x + 4 For that equation, the process would be something like: The first exponent coefficient (you call this 'deg') is 1; it will be increased 1 to 2; You also divide by the new coefficient: Thus: (4/2)x^2 + (4/1)x + k = 2x^2 + 4x + k There's always a k (because that x^0 component drops off when you do the differential). -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From cooler12001@yahoo.com Wed May 2 07:45:13 2001 From: cooler12001@yahoo.com (Matthews James) Date: Tue, 1 May 2001 23:45:13 -0700 (PDT) Subject: [Tutor] python and html Message-ID: <20010502064513.32865.qmail@web11401.mail.yahoo.com> can you use python in html __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ From cooler12001@yahoo.com Wed May 2 07:49:15 2001 From: cooler12001@yahoo.com (Matthews James) Date: Tue, 1 May 2001 23:49:15 -0700 (PDT) Subject: [Tutor] help turningTkinter programs in to exe Message-ID: <20010502064915.79578.qmail@web11402.mail.yahoo.com> does anyone know how to turn a program that has Tkinter in it into a exe one. Py2exe will not have anything to do with them __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ From dyoo@hkn.eecs.berkeley.edu Wed May 2 08:24:51 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 2 May 2001 00:24:51 -0700 (PDT) Subject: [Tutor] integration of polynomials in Python [And SICP for free!] In-Reply-To: Message-ID: On Wed, 2 May 2001, Julieta Rangel wrote: > I finally finished the differentiation program. What changes should I make > so that instead of differentiating, my program integrates polynomials. Can > anyone help? Here you have my finished program. It is not the best program > you'll ever see :) but I'm very proud of it. It took me forever to put it > together, eventhough I had to ask you guys for help in writing every line. > Thanks a lot! :) Anyway, here you have the program. What can I do to make > it integrate? Let's have this placed in Useless Python. If you ever write a script that you're happy with, feel free to contribute it to the Useless Python repository. It's at: http://www.lowerstandard.com/python/pythonsource.html You program looks good; I'm happy that the differentiation works ok. Integration is actually not too bad either; think about what happens when we integrate polynomials: f(x) = 1x^3 + 2x^2 + 3x + 4 or, if we reverse the order of the coefficients: f(x) = 4 + 3x + 2x^2 + 1x^3 If we integrate this, we end up with the polynomial: f(x) = 4 3 2 2 3 1 4 - x + - x^ + - x^ + - x^ 1 2 3 4 If you try a few examples by hand, I think you'll figure out a way to fiddle with your list of coefficients to get things working. Also, I second Alan's recommendation on Structure and Interpretation of Computer Programs: it's one of the best CS books I've read. You seem to have a mathy slant, and I think you'll enjoy this book a LOT. The authors are really generous folk: the book is actually published online as well! http://mitpress.mit.edu/sicp/ So you don't even need to leave the house... although that's not quite a good thing. Take a nice walk first; you'll need to keep your head clear while reading this stuff. *grin* If you like the book, buy it; it has a nice feel. Good luck! From dyoo@hkn.eecs.berkeley.edu Wed May 2 08:26:55 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 2 May 2001 00:26:55 -0700 (PDT) Subject: [Tutor] help turningTkinter programs in to exe In-Reply-To: <20010502064915.79578.qmail@web11402.mail.yahoo.com> Message-ID: On Tue, 1 May 2001, Matthews James wrote: > does anyone know how to turn a program that has > Tkinter in it into a exe one. Py2exe will not > have anything to do with them Gordon MacMillian's Python Installer is supposed to be more powerful than py2exe. You can find it here: http://www.mcmillan-inc.com/install1.html A few people on tutor have been playing around with Installer, so you're in good company. From dyoo@hkn.eecs.berkeley.edu Wed May 2 08:50:14 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 2 May 2001 00:50:14 -0700 (PDT) Subject: [Tutor] FieldStorage solution summary In-Reply-To: <200105011309.JAA17875@birds.us.itd.umich.edu> Message-ID: On Tue, 1 May 2001, Lance E Sloan wrote: > With the suggestions I had gotten about converting FieldStorage to a > dictionary, I came up with this function, dictcat, that will take any > number of dictionaries or FieldStorage objects and concatenate them > into a single dictionary. When you run this as-is, it will print out > the results of the examples: The code looks good. The only thing I could argue for is: > if (type(d) == type({})): which might be better off as types.DictType, but they, we've had a lot of religious argument about this. I'm not sure if dictcat() should have to worry about non-dictionaries; it might be better off giving a message that dictcat() needs to take a dictonary-like object; otherwise, it might obscure some errors that the programmer might forget to check. From dyoo@hkn.eecs.berkeley.edu Wed May 2 08:55:36 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 2 May 2001 00:55:36 -0700 (PDT) Subject: [Tutor] FieldStorage solution summary In-Reply-To: Message-ID: On Wed, 2 May 2001, Daniel Yoo wrote: > which might be better off as types.DictType, but they, we've had a lot of ^^^^ Umm... meant to say "then". > dictonary-like object; otherwise, it might obscure some errors that the ^^^^^^^^^ ... and "dictionary". Apologies; I just took some Themo-Flu, and the stuff is making me drowsy and stupid. From wheelege@tsn.cc Wed May 2 09:57:13 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Wed, 2 May 2001 18:57:13 +1000 Subject: [Tutor] help turningTkinter programs in to exe References: <20010502064915.79578.qmail@web11402.mail.yahoo.com> Message-ID: <03dd01c0d2e5$e1f2bfa0$0200a8c0@ACE> > does anyone know how to turn a program that has > Tkinter in it into a exe one. Py2exe will not > have anything to do with them > Are you sure? Do you have python 2.0 with the latest version of py2exe? I have made plenty of tkinter programs into standalone distributions using py2exe. Give me more detail on what you are doing, and I'll see if I can find out what it is your doing wrong. Glen. From alan.gauld@bt.com Wed May 2 10:34:09 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Wed, 2 May 2001 10:34:09 +0100 Subject: [Tutor] python and html Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D73D@mbtlipnt02.btlabs.bt.co.uk> > can you use python in html yes, look at PSP, Zope, PMZ, Active Scripting etc See the CGI special interest group/topic too. Now what do you actually want to do? Alan G. From lsloan@umich.edu Wed May 2 13:38:28 2001 From: lsloan@umich.edu (Lance E Sloan) Date: Wed, 02 May 2001 08:38:28 -0400 Subject: [Tutor] FieldStorage solution summary In-Reply-To: Your message of "Wed, 02 May 2001 00:50:14 PDT." Message-ID: <200105021238.IAA03791@birds.us.itd.umich.edu> Daniel Yoo wrote: > I'm not sure if dictcat() should have to worry about non-dictionaries; it > might be better off giving a message that dictcat() needs to take a > dictonary-like object; otherwise, it might obscure some errors that the > programmer might forget to check. I admit the name of the function might be misleading, but its primary purpose in life is to convert FieldStorage to dictionary. Do you mean that I should split this into two functions, one for converting FieldStorage and the other for concatenating dictionaries? Or do you mean that I should have the function throw an exception if it is passed an argument that's not a dictionary or FieldStorage? -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Perl & Python CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From Vladimir.Denis@olsinc.net Wed May 2 15:07:26 2001 From: Vladimir.Denis@olsinc.net (Vladimir.Denis@olsinc.net) Date: Wed, 2 May 2001 10:07:26 -0400 Subject: [Tutor] searching a file for a specific word Message-ID: Hello everyone, this is my first attempt at programming and I have chosen python because I was told that it's easy to learn. In any event I thought that for my first script I would write a program that would be able to find a word or words in a file. The problem is I'm stuck. Below you will find what I have done so far and any advice will be appreciated. As you will note, I have figured out how to get the file name, the words to be searched for, but I don't know how to actually search for the words. The only thing I could think of so far is to use the os module and use the grep command but I'm sure there's another way and I can't figure it out. Since I'm new to programming I am not too familiar with strings (and I'm sure this is probably part of the solution). #/usr/bin/python # this script will print specific words from a file # (most likely a log file) to desktop import os, string, sys names = [] logf = sys.argv[-1] ############################################################### ## opens the /var/log/messages file by default or other file ## ############################################################### if (logf[0:1] == "/"] filename = logf names.append(sys.argv[1:-1] found = open("filename","r") else: filename = "/var/log/messages" names.append(sys.argv[1:-1] From bdupire@seatech.fau.edu Wed May 2 15:10:01 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Wed, 02 May 2001 10:10:01 -0400 Subject: [Tutor] searching a file for a specific word References: Message-ID: <3AF01539.708FB7D0@seatech.fau.edu> The following function does something similar.... It looks for a word in a web page (it was post by Remco a few weeks ago) You can transpose it to your problem The open function returns a file object you can read from... page is actually all the text in the file... (here the webpage) use string.find... it's a convenient function for your problem...:o) def find_word(url, word): import urllib, string page = urllib.URLopener().open(url).read() if string.find(page, word) != -1: return 1 else: return 0 Benoit (tks Remco.. :o) ) Vladimir.Denis@olsinc.net wrote: > Hello everyone, this is my first attempt at programming and I have chosen > python because I was told that it's easy to learn. In any event I thought > that for my first script I would write a program that would be able to find > a word or words in a file. The problem is I'm stuck. Below you will find > what I have done so far and any advice will be appreciated. As you will > note, I have figured out how to get the file name, the words to be searched > for, but I don't know how to actually search for the words. The only thing > I could think of so far is to use the os module and use the grep command > but I'm sure there's another way and I can't figure it out. Since I'm new > to programming I am not too familiar with strings (and I'm sure this is > probably part of the solution). > > #/usr/bin/python > > # this script will print specific words from a file > # (most likely a log file) to desktop > > import os, string, sys > > names = [] > logf = sys.argv[-1] > > ############################################################### > ## opens the /var/log/messages file by default or other file ## > ############################################################### > > if (logf[0:1] == "/"] > filename = logf > names.append(sys.argv[1:-1] > found = open("filename","r") > > else: > filename = "/var/log/messages" > names.append(sys.argv[1:-1] > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From julieta_rangel@hotmail.com Wed May 2 17:58:22 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Wed, 02 May 2001 11:58:22 -0500 Subject: [Tutor] rational number representation in Python Message-ID: To integrate a polynomial, say 3x^2+7x+4, we have to add one to the exponent and then divide the coefficient by this result. For example, in our polynomial above, we would have to add 1 to our exponent so that we get 3.Then we divide our coefficient by this result (3/3=1), so our new coefficient is going to be one. We do the same thing to the next term; we add one to our exponent, which will give us 2, and then divide the coefficient by 2 (7/2). And finally we add one to the exponent of x^0, so this will give us 1 and we divide 4 by 1. So that we get apolynomial looking like this: (3/3)x^3 + (7/2)x^2 + (4/1)x or better yet, x^3 + (7/2)x^2 + 4x. My problem is, once I know the degree of my polynomial and the coefficients of my polynomial, how can I do all these operations? My problem is representing rational numbers, ie,(7/2). Because my result of this division is not an integer, I don't want Python to divide. I want (3/3) to be divided, (4/1) to be divided, but I want (7/2) to be left alone. How can I do this? Can anyone help? Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From iamgod@st.jyu.fi Wed May 2 18:11:11 2001 From: iamgod@st.jyu.fi (Risto Peranen) Date: Wed, 2 May 2001 20:11:11 +0300 (EEST) Subject: [Tutor] Dynamic web-pages and protected attributes In-Reply-To: Message-ID: Well, I just a beginner in python. Is it possible to make dynamic web-pages with python? I have really had enough so called "hard" and "real" programming and personally I think Java is nice but far too slow. I'm also wondering is there any way to protect attributes in python's classes. It would be nice to make safe classes for python. class MyClass: protected: #something nice and not so interesting for other users public: #somethin public Risto Peranen 040 756 94 12 iamgod@st.jyu.fi "ihminen on lihaa, heikko ja katoavainen" - moos:6:3 From sheila@thinkspot.net Wed May 2 18:17:37 2001 From: sheila@thinkspot.net (Sheila King) Date: Wed, 02 May 2001 10:17:37 -0700 Subject: [Tutor] rational number representation in Python In-Reply-To: References: Message-ID: <5B6B5744C4A@kserver.org> On Wed, 02 May 2001 11:58:22 -0500, "Julieta Rangel" wrote about [Tutor] rational number representation in Python: :Because my result of :this division is not an integer, I don't want Python to divide. I want :(3/3) to be divided, (4/1) to be divided, but I want (7/2) to be left alone. : How can I do this? Can anyone help? In comp.lang.python, there has been talk about an experimental number class that includes rational numbers. (I don't remember the details right now.) You could possibly use something like that. Or, it might be instructive to write your own rational number class. For reducing fractions, like 3/3 or even 9/3, etc... a useful algorithm is called Euclid's Algorithm. You should be able to find the algorithm in a book on algorithms fairly easily. It will find the GCF for you, then you can divide it out of the numerator and denominator. I would make a test, that whenever the denominator is 1, to just stop printing it, and let the number be output as 4 instead of 4/1. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From kromag@nsacom.net Wed May 2 22:43:20 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Wed, 2 May 2001 14:43:20 -0700 (PDT) Subject: [Tutor] starting a tkinter window maximized Message-ID: <200105022143.f42LhKo22431@pop.nsacom.net> The subject pretty much says it all! How does one tell a tkinter window to start maximized in windows or X? From NHYTRO@compuserve.com Wed May 2 23:33:11 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Wed, 2 May 2001 18:33:11 -0400 Subject: [Tutor] List problem Message-ID: <200105021833_MC2-CEB3-D925@compuserve.com> Hi all! from my database per CGI I get this list: allrows =3D [(1, 'sharriff', 'sh1', 'sharriff', 'admin', 'c:\\minics\\db\\users\\aina', 'template2', 'Aina Inc.', 'Gutenbergstr. 42', '41564', 'Kaarst', 'NRW', 'Germany', '02131- 3839- 412', '02131-3839-599', '0177-12345678', 'sa@med-iq.de', '10.104.98.70', 'Mr. Sharriff Aina', 'Aina', 'Home,Aktuelles,None')] = I=B4ve coded a login script (CGI) that does a very simple comparism of fi= elds from the database with data captured from a form ### code start ### fields =3D allrows[0] if fields[3] =3D=3D usernamevalue and fields[4] =3D=3D passwordvalue : .... print block1, # blocks of HTML code .... print fields[18], .... print block2 .... print usernamevalue, ....print block3 elif fields[3] !=3D usernamevalue and fields[4] !=3D passwordvalue : ....print errorpage #### code end #### the problem is, when correct values are entered in the form everything works fine as soon as one enters a false password or false username I get= this error "Traceback (most recent call last): File "cgi-bin/login.cgi", line 119, in ? fields =3D allrows[0] IndexError: list index out of range If its out of range why does it work corretly when the data filled in is correct? the mid boggling X-files part of it is that it works when I simulate this code in the Python console!! Have I overlooked something? I thought it was due to fatigue yesterday, b= ut I couldn=B4t get it to budge today, its worn me out. = Could someone throw me a life jacket? I=B4m just drifting here.. Thanks Sharriff From vlindberg@verio.net Wed May 2 23:54:58 2001 From: vlindberg@verio.net (VanL) Date: Wed, 02 May 2001 16:54:58 -0600 Subject: [Tutor] Moving email between servers Message-ID: <3AF09042.8DCDF8E7@verio.net> Hello, I have got what is pretty simple problem conceptually, but I don't know how to implement it. I know that some of the semantics aren't quite right -- that is OK. I will note where the problems are. (Pseudocode) M1 = poplib.POP3('server1') M2 = imaplib.IMAP4('server2') M1.login(user,pass) M2.login(user,pass) folders = M1.listfolders() ^^^^^^^^^^^^^^^^^^^^^^^^^^ # Get a list of a folders PROBLEM: I can't find out how to get the contents of anything but the inbox. for folder in folders: # create the folder on the new server M2.create(folder) # get all messages, move them to the new server numMsgs = len(M1.list()[1]) for i in range(numMsgs): for j in M1.retr(i+1)[1]: M2.append(j) M1.close() M2.close() Essentially, I want to recursively copy all mailfolders and messages from one server to another. I only have POP3 access to the first server. Any ideas? I have looked at the poplib module, but I can't figure out how to do it. Thanks, VanL From julieta_rangel@hotmail.com Thu May 3 01:17:11 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Wed, 02 May 2001 19:17:11 -0500 Subject: [Tutor] attaching the first element in a list to a string Message-ID: I have this problem. I'm trying to write a program that calculates the integral of a polynomial. This is what I have so far: import string class Poly: def __init__ ( self, v='x' , c = [0]): """__init__(): Initializes a polynomial Default variable is x Default polynomial is zero""" self.var = v self.coef = c self.deg = len(c)-1 self.length = len(c) def __str__ (self): """__str__(): Converts a polynomial into a string""" x = `self.coef[0]` for i in range (1, self.deg+1): x = x + "+" +`self.coef[i]` + self.var + "^" + `i` return x class Poly2: def __init__ (self, v='x' , c = [0]): """__init__(): Initializes a polynomial Default variable is x Default polynomial is zero""" self.var = v self.pc = c self.deg =len(c)-1 self.length = len(c) def __str__(self): """__str__(): Converts a second polynomial into a string""" x = `self.pc[0]` for i in range (0, self.deg+1): x = x + "+" +`self.pc[i]`+ self.var + "^" +`i+2` return x def Integrate(p): """Input: an instance of a polynommial Output: a polynomial that is the integral of the input polynomial Side Effects: None""" pv=p.var pc=[] for i in range(0,p.deg): I=p.coef[i+1]/float(i+2) pc.append(I) return Poly2 (v=pv,c=pc) degree = input('Enter the degree of your polynomial') coef=[] for i in range (0,degree + 1): coefficient = input('Enter the coefficient for x^ %i ? ' %i) coef.append(coefficient)#attach the coefficient entered to the end of the #list named coef. s= Poly (c = coef) t= Integrate(s) # This is some code to test new functions print "The integral of %s is: \n %s" % (s,t) print " " My problem is that when I run it I get this: >>>reload(poly1) Enter the degree of your polynomial3 Enter the coefficient for x^ 0 ? 2 Enter the coefficient for x^ 1 ? 5 Enter the coefficient for x^ 2 ? 6 Enter the coefficient for x^ 3 ? 1 The integral of 2+5x^1+6x^2+1x^3 is: 2.5+2.5x^2+2.0x^3+0.25x^4 As you can see, the answer would be right if it weren't for the first term in the polynomial. The first term should be a 2x, so the answer should look like this: 2x^1+2.5x^2+2x^3+0.25x^4. Can anyone help me fix this problem? I think that I need to find a way to have the first term on the list labeled pc, which is 2 to be taken into consideration on the string representing the polynomial. Am I right? If so, How can I accomplish this? Also, I need to find a way so that when the coefficient of x^0 ==0 , the output should display a constant c along with the result, so that the answer looks like c+2.5x^2+2x^3+0.23x^4. Can anyone guide me in the right direction? All inputs or comments about my program are welcomed and appreciated. Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From vlindberg@verio.net Thu May 3 01:28:29 2001 From: vlindberg@verio.net (VanL) Date: Wed, 02 May 2001 18:28:29 -0600 Subject: [Tutor] Moving email between servers References: <3AF09042.8DCDF8E7@verio.net> Message-ID: <3AF0A62D.AF87F6E4@verio.net> OK, after a little more research, the question has changed. Evidently, there is no such thing as a POP3 "folder". They are, as far as the mail client is concerned, just a named local message store. Applications which support POP3 folders actually download the file, sort it and store it locally. However, the mail that I am interested in is still on a server. (One that supports "folders".) Is there any way to specify which mailbox to open? Thanks, VanL From dyoo@hkn.eecs.berkeley.edu Thu May 3 02:12:02 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 2 May 2001 18:12:02 -0700 (PDT) Subject: [Tutor] List problem In-Reply-To: <200105021833_MC2-CEB3-D925@compuserve.com> Message-ID: On Wed, 2 May 2001, Sharriff Aina wrote: > ### code start ### > > fields = allrows[0] > if fields[3] == usernamevalue and fields[4] == passwordvalue : > .... print block1, # blocks of HTML code > .... print fields[18], > .... print block2 > .... print usernamevalue, > ....print block3 > elif fields[3] != usernamevalue and fields[4] != passwordvalue : > ....print errorpage > > #### code end #### It looks like this is code that you typed at the interpreter. Is this the same code you're using within the CGI script? > the problem is, when correct values are entered in the form everything > works fine as soon as one enters a false password or false username I get > this error > > "Traceback (most recent call last): > File "cgi-bin/login.cgi", line 119, in ? > fields = allrows[0] > IndexError: list index out of range I'm guessing that if they enter in a bad password or username, that the allrows list is empty. Can you show us the code that grabs allrows? It looks like you're doing a "SELECT" sql command to grab all the columns. However, if it can't find a person within the database, it should probably return no rows at all. > If its out of range why does it work corretly when the data filled in is > correct? the mid boggling X-files part of it is that it works when I > simulate this code in the Python console!! We'll need to see how you're assigning allrows. If the username/password's misspelled, it looks like it won't be able to fetch any rows. You code probably needs to take care of this case; it can't immediately fetch the first element of allrows. Hope this helps! From tbaruch@mindless.com Thu May 3 02:30:08 2001 From: tbaruch@mindless.com (Timothy M. Brauch) Date: Wed, 02 May 2001 21:30:08 -0400 Subject: [Tutor] Processor Simulator Message-ID: <3AF0B4A0.7DC0E1B2@mindless.com> I have a project for my comp-sci class. I have to design a simulator for a processor, and I've decided to use Python. So, my question is, does anyone have any suggestions as to how to go about doing this? Also, I have to write simple files and load them into my simulator. My initial thoughts are to create a class with a bunch of function definitions for different processes. Such as add() and sub() and mul(), etc. I also have to have a display window showing register enteries, which that I think I can do fairly easily. I was thinking of using the latest VPython which has a text function (I am doing this mostly because I have no experience with TK, otherwise I would use it, but right now I don't have the time to learn it). As for the files, I would use something like readlines and string.split to break up my commands kept in the external file. I think I can handle that as well. If anyone has any suggestions or can offer any help, let me know. I feel like this might be one of the biggest projects I have undertaken so far. - Tim From bdupire@seatech.fau.edu Thu May 3 02:33:02 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Wed, 02 May 2001 21:33:02 -0400 Subject: [Tutor] attaching the first element in a list to a string References: Message-ID: <3AF0B54E.EB0D53DC@seatech.fau.edu> I modified your program in this way: class Poly: def __init__ ( self, v='x' , c = [0]): """__init__(): Initializes a polynomial Default variable is x Default polynomial is zero""" self.var = v self.coef = c self.deg = len(c)-1 self.length = len(c) def __str__ (self): """__str__(): Converts a polynomial into a string""" x = `self.coef[0]` for i in range (1, self.deg+1): x = x + "+" +`self.coef[i]` + self.var + "^" + `i` return x def integrate(self): """Input: an instance of a polynommial Output: a polynomial that is the integral of the input polynomial Side Effects: None""" coef=[0] self.deg= self.deg +1 for i in range(0,self.deg): coef.append(self.coef[i]/float(i+1)) self.coef= coef degree = input('Enter the degree of your polynomial') coef=[] for i in range (0,degree + 1): coefficient = input('Enter the coefficient for x^ %i ? ' %i) coef.append(coefficient) s= Poly (c = coef) The result is now the good one: >>> reload(poly) Enter the degree of your polynomial3 Enter the coefficient for x^ 0 ? 2 Enter the coefficient for x^ 1 ? 5 Enter the coefficient for x^ 2 ? 6 Enter the coefficient for x^ 3 ? 1 >>> poly.s.integrate() >>> print poly.s 0+2.0x^1+2.5x^2+2.0x^3+0.25x^4 What are the difference with your program? integrate is now a method of the class Poly so i can use it like this... s= Poly( c=[1 5 6]) # here, we use __init__ print s # here we use __str__ s.integrate() # guess what ? So the first argument of integrate() is now 'self' (the polynome itself) I first increment the degree (because that's the definition of the integration of a polynom) The first coeff should normally be 'k', we need an initial condition to set it, so for now i put 0 next coeff = coeff (degree 0) / (0+1) next coeff = coeff (degree 1)/ (1+1) etc... When i have the new list of coeff, i set it for the current polynom ( self.coef= coef) You can also add your derivation function as a method, and use it like s.derivate() Benoit Julieta Rangel wrote: > I have this problem. I'm trying to write a program that calculates the > integral of a polynomial. This is what I have so far: > > import string > class Poly: > def __init__ ( self, v='x' , c = [0]): > """__init__(): > Initializes a polynomial > Default variable is x > Default polynomial is zero""" > self.var = v > self.coef = c > self.deg = len(c)-1 > self.length = len(c) > def __str__ (self): > """__str__(): > Converts a polynomial into a string""" > x = `self.coef[0]` > for i in range (1, self.deg+1): > x = x + "+" +`self.coef[i]` + self.var + "^" + `i` > return x > > class Poly2: > def __init__ (self, v='x' , c = [0]): > """__init__(): > Initializes a polynomial > Default variable is x > Default polynomial is zero""" > self.var = v > self.pc = c > self.deg =len(c)-1 > self.length = len(c) > def __str__(self): > """__str__(): > Converts a second polynomial into a string""" > x = `self.pc[0]` > for i in range (0, self.deg+1): > x = x + "+" +`self.pc[i]`+ self.var + "^" +`i+2` > return x > > def Integrate(p): > """Input: an instance of a polynommial > Output: a polynomial that is the integral of the input polynomial > Side Effects: None""" > pv=p.var > pc=[] > for i in range(0,p.deg): > I=p.coef[i+1]/float(i+2) > pc.append(I) > return Poly2 (v=pv,c=pc) > > degree = input('Enter the degree of your polynomial') > coef=[] > for i in range (0,degree + 1): > coefficient = input('Enter the coefficient for x^ %i ? ' %i) > coef.append(coefficient)#attach the coefficient entered to the end of > the > #list named coef. > > s= Poly (c = coef) > t= Integrate(s) > # This is some code to test new functions > > print "The integral of %s is: \n %s" % (s,t) > print " " > > My problem is that when I run it I get this: > > >>>reload(poly1) > Enter the degree of your polynomial3 > Enter the coefficient for x^ 0 ? 2 > Enter the coefficient for x^ 1 ? 5 > Enter the coefficient for x^ 2 ? 6 > Enter the coefficient for x^ 3 ? 1 > The integral of 2+5x^1+6x^2+1x^3 is: > 2.5+2.5x^2+2.0x^3+0.25x^4 > > As you can see, the answer would be right if it weren't for the first term > in the polynomial. The first term should be a 2x, so the answer should look > like this: 2x^1+2.5x^2+2x^3+0.25x^4. Can anyone help me fix this problem? > I think that I need to find a way to have the first term on the list labeled > pc, which is 2 to be taken into consideration on the string representing the > polynomial. Am I right? If so, How can I accomplish this? Also, I need to > find a way so that when the coefficient of x^0 ==0 , the output should > display a constant c along with the result, so that the answer looks like > c+2.5x^2+2x^3+0.23x^4. > Can anyone guide me in the right direction? All inputs or comments about my > program are welcomed and appreciated. > > Julieta > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From sheila@thinkspot.net Thu May 3 02:42:04 2001 From: sheila@thinkspot.net (Sheila King) Date: Wed, 02 May 2001 18:42:04 -0700 Subject: [Tutor] attaching the first element in a list to a string In-Reply-To: References: Message-ID: <17D48B13DC4@kserver.org> On Wed, 02 May 2001 19:17:11 -0500, "Julieta Rangel" wrote about [Tutor] attaching the first element in a list to a string: :The integral of 2+5x^1+6x^2+1x^3 is: :2.5+2.5x^2+2.0x^3+0.25x^4 : :As you can see, the answer would be right if it weren't for the first term :in the polynomial. The first term should be a 2x, so the answer should look :like this: 2x^1+2.5x^2+2x^3+0.25x^4. Can anyone help me fix this problem? :I think that I need to find a way to have the first term on the list labeled :pc, which is 2 to be taken into consideration on the string representing the :polynomial. Am I right? If so, How can I accomplish this? Also, I need to :find a way so that when the coefficient of x^0 ==0 , the output should :display a constant c along with the result, so that the answer looks like :c+2.5x^2+2x^3+0.23x^4. I won't respond to the programming issues, since Benoit has already responded. I'll wait and see if his help solves your problems. But I'd like to address a math issue: Shouldn't you have a +c constant added to your integral in *every* case? NOT just when the coefficient of x^0 is equal to 0. (BTW: the question is rhetorical. I KNOW that you *should* have it there...typed the calculus teacher...) -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From arazak@kansai.com.my Thu May 3 04:07:54 2001 From: arazak@kansai.com.my (Mr. Razak) Date: Thu, 3 May 2001 11:07:54 +0800 Subject: [Tutor] Few simple question. Message-ID: <001501c0d37e$424a9ce0$6a01a8c0@com.my> This is a multi-part message in MIME format. ------=_NextPart_000_0012_01C0D3C1.4D8B5660 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Actually I'm new in this language, so I really sorry if I'm asking a = stupid question. 1). I want to know how to change colour, i mean how to used colour in = python language. 2). How to used coordinate system, or may be there is a module i can = used to help me. For example on the computer screen at a location = row=3D5, column 35, I want to print 'Hello world'. How to do that. 3). How to create box and how place it on the computer screen on the = desirerable location. Thank's. ------=_NextPart_000_0012_01C0D3C1.4D8B5660 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Actually I'm new in this language, so I = really=20 sorry if I'm asking a stupid question.
 
1). I want to know how to change = colour, i mean how=20 to used colour in python language.
 
2). How to used coordinate system, or = may be there=20 is a module i can used to help me. For example on the computer screen at = a=20 location row=3D5, column 35, I want to print 'Hello world'. How to do=20 that.
 
3). How to create box and how place it = on the=20 computer screen on the desirerable location.
 
Thank's.
------=_NextPart_000_0012_01C0D3C1.4D8B5660-- From virketis@fas.harvard.edu Thu May 3 04:43:21 2001 From: virketis@fas.harvard.edu (Pijus Virketis) Date: Wed, 02 May 2001 23:43:21 -0400 Subject: [Tutor] bizare Tkinter error In-Reply-To: Message-ID: <200105030339.f433dFQ31313@smtp4.fas.harvard.edu> I am writing a class assignment right now, and I have run into a most peculiar bug. I know where it is, but I have absolutely no clue why it occurs. Here is the relevant bit of my code: class EditFrame: def __init__(self, master): ### Set up prompt frame, list frame, edit frame p_f = l_f = e_f = Frame(master) <----- I assign all three frames simultaneously. This will prove to be the for f in [p_f, l_f, e_f]: <------ problematic bit. f.pack() ## Irrelevant stuff ## # Data entry loop : set up StringVars self.name = self.wage_rate = self.ptd = StringVar() Vars = [self.name, self.wage_rate, self.ptd] Ques = ["Name: ", "Wage rate: ", "Amount paid to date: "] Entries = [] # Data loop for position in range(len(Ques)): self.prompt = Label(e_f, text = Ques[position], font = "Arial 15", justify = "right") self.entry = Entry(e_f, width=20, font = "Arial 15", textvariable = Vars[position]) # Store Entry widgets in a list for future reference; nothing else needs to be manipulated and thus is not saved Entries.append(self.entry) # Grid the the data loop widgets self.prompt.grid(row = (position+1), column = 0) self.entry.grid(row = (position+1), column = 1) If I run the code as is, the program crashes after cycling through the Data loop (last loop in the snip). If I go back to the beginning, and explicitly say e_f = Frame(master) then the loop goes through just fine and does what it's supposed to do. For the life of me, I cannot understand, why assigning the third frame together with the first two would do this ... Perhaps I am missing something here? BTW, I am using Python 2.1 with the latest Tkinter. Thank you, Pijus ---------------------------------------------------------------------------- ------------------- Please have a look at my weblog at www.fas.harvard.edu/~virketis. From virketis@fas.harvard.edu Thu May 3 05:06:23 2001 From: virketis@fas.harvard.edu (Pijus Virketis) Date: Thu, 03 May 2001 00:06:23 -0400 Subject: [Tutor] Few simple question Message-ID: <200105030402.f4342IQ24037@smtp4.fas.harvard.edu> --=====================_204520498==_.ALT Content-Type: text/plain; charset="us-ascii" All the tasks you described can be accomplished with a GUI creation module called Tkinter, which interfaces to the Tk GUI library. A tutorial can by found here: http://www.pythonware.com/library/tkinter/introduction/. >1) I want to know how to change colour, i mean how to used colour in >python language. Most Tkinter widgets take a argument background or foreground. As in: label = Label(root, text="It's just an example", background = "red") This will create a red field with the black letters "It's just an example" on it. >2). How to used coordinate system, or may be there is a module i can = >used to help me. For example on the computer screen at a location = >row=3D5, column 35, I want to print 'Hello world'. How to do that. A widget called Canvas handles all the drawing in Tk. Here's the passage from the tutorial about the coordinate system there: "The Canvas widget uses two coordinate systems; the window coordinate system (with (0, 0) in the upper left corner), and a canvas coordinate system in which the items are drawn. By scrolling the canvas, you can specify which part of the canvas coordinate system to show in the window." If you just want to print things out on a screen, that's a bit different. You can simple use the Label widget, as shown above, and then grid() it to your needed location. So: label = Label(root, text="Hello world", background = "red", font="Times 20") label.grid(row=35, column=35) >3). How to create box and how place it on the computer screen on the = >desirerable location. If you want to create a box, first you need to initialise a root window and pack a Canvas widget in it: root = Tk() c = Canvas(root) c.pack() and then you can just create a box in your canvas: c.create_rectangle(10,10,200,200, fill="red") This will create a red rectange within the "box" of the specified size. In our case, the rectangle and box are equivalent. But if you were creating an oval shape, then the "box" would bound the oval's dimensions. Hope this helps. Pijus ---------------------------------------------------------------------------- ------------------- Please have a look at my weblog at www.fas.harvard.edu/~virketis. --=====================_204520498==_.ALT Content-Type: text/html; charset="us-ascii" All the tasks you described can be accomplished with a GUI creation module called Tkinter, which interfaces to the Tk GUI library. A tutorial can by found here: http://www.pythonware.com/library/tkinter/introduction/.

>1) I want to know how to change colour, i mean how to used colour in
>python language.

Most Tkinter widgets take a argument  background or foreground. As in:

label = Label(root, text="It's just an example", background = "red")

This will create a red field with the black letters "It's just an example" on it.

>2). How to used coordinate system, or may be there is a module i can =
>used to help me. For example on the computer screen at a location =
>row=3D5, column 35, I want to print 'Hello world'. How to do that.

A widget called Canvas handles all the drawing in Tk. Here's the passage from the tutorial about the coordinate system there:

"The Canvas widget uses two coordinate systems; the window coordinate system (with (0, 0) in the upper left corner), and a canvas coordinate system in which the items are drawn. By scrolling the canvas, you can specify which part of the canvas coordinate system to show in the window."

If you just want to print things out on a screen, that's a bit different. You can simple use the Label widget, as shown above, and then grid() it to your needed location. So:

label = Label(root, text="Hello world", background = "red", font="Times 20")
label.grid(row=35, column=35)

>3). How to create box and how place it on the computer screen on the =
>desirerable location.

If you want to create a box, first you need to initialise a root window and pack a Canvas widget in it:

root = Tk()
c = Canvas(root)
c.pack()

and then you can just create a box in your canvas:

c.create_rectangle(10,10,200,200, fill="red")

This will create a red rectange within the "box" of the specified size. In our case, the rectangle and box are equivalent. But if you were creating an oval shape, then the "box" would bound the oval's dimensions.

Hope this helps.

Pijus





-----------------------------------------------------------------------------------------------
Please have a look at my weblog at www.fas.harvard.edu/~virketis. --=====================_204520498==_.ALT-- From julieta_rangel@hotmail.com Thu May 3 05:08:42 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Wed, 02 May 2001 23:08:42 -0500 Subject: [Tutor] attaching the first element in a list to a string Message-ID: This modification to the program works well in calculating the integral, but it does not print it out when running the program. When you inputed poly.s.integrate() followed by print poly.s (In Python Shell), the integral is printed. What command should we include in the program to make it print out automatically while running it. If I include these commands in the actual program, they don't work as they do in Python Shell. Thanks for your help. Julieta >From: Benoit Dupire >To: Julieta Rangel >CC: tutor@python.org >Subject: Re: [Tutor] attaching the first element in a list to a string >Date: Wed, 02 May 2001 21:33:02 -0400 > >I modified your program in this way: > >class Poly: > def __init__ ( self, v='x' , c = [0]): > """__init__(): > Initializes a polynomial > Default variable is x > Default polynomial is zero""" > self.var = v > self.coef = c > self.deg = len(c)-1 > self.length = len(c) > def __str__ (self): > """__str__(): > Converts a polynomial into a string""" > x = `self.coef[0]` > for i in range (1, self.deg+1): > x = x + "+" +`self.coef[i]` + self.var + "^" + `i` > return x > > > def integrate(self): > """Input: an instance of a polynommial > Output: a polynomial that is the integral of the input polynomial > Side Effects: None""" > > coef=[0] > self.deg= self.deg +1 > for i in range(0,self.deg): > coef.append(self.coef[i]/float(i+1)) > self.coef= coef > > >degree = input('Enter the degree of your polynomial') >coef=[] >for i in range (0,degree + 1): > coefficient = input('Enter the coefficient for x^ %i ? ' %i) > coef.append(coefficient) > >s= Poly (c = coef) > > > > >The result is now the good one: > >>> reload(poly) >Enter the degree of your polynomial3 >Enter the coefficient for x^ 0 ? 2 >Enter the coefficient for x^ 1 ? 5 >Enter the coefficient for x^ 2 ? 6 >Enter the coefficient for x^ 3 ? 1 > > >>> poly.s.integrate() > >>> print poly.s >0+2.0x^1+2.5x^2+2.0x^3+0.25x^4 > > >What are the difference with your program? > >integrate is now a method of the class Poly >so i can use it like this... > >s= Poly( c=[1 5 6]) # here, we use __init__ >print s # here we use __str__ >s.integrate() # guess what ? > >So the first argument of integrate() is now 'self' (the polynome itself) >I first increment the degree (because that's the definition of the >integration >of a polynom) >The first coeff should normally be 'k', we need an initial condition to set >it, >so for now i put 0 >next coeff = coeff (degree 0) / (0+1) >next coeff = coeff (degree 1)/ (1+1) >etc... >When i have the new list of coeff, i set it for the current polynom ( >self.coef= coef) > >You can also add your derivation function as a method, and use it like >s.derivate() > >Benoit > > > > > > > >Julieta Rangel wrote: > > > I have this problem. I'm trying to write a program that calculates the > > integral of a polynomial. This is what I have so far: > > > > import string > > class Poly: > > def __init__ ( self, v='x' , c = [0]): > > """__init__(): > > Initializes a polynomial > > Default variable is x > > Default polynomial is zero""" > > self.var = v > > self.coef = c > > self.deg = len(c)-1 > > self.length = len(c) > > def __str__ (self): > > """__str__(): > > Converts a polynomial into a string""" > > x = `self.coef[0]` > > for i in range (1, self.deg+1): > > x = x + "+" +`self.coef[i]` + self.var + "^" + `i` > > return x > > > > class Poly2: > > def __init__ (self, v='x' , c = [0]): > > """__init__(): > > Initializes a polynomial > > Default variable is x > > Default polynomial is zero""" > > self.var = v > > self.pc = c > > self.deg =len(c)-1 > > self.length = len(c) > > def __str__(self): > > """__str__(): > > Converts a second polynomial into a string""" > > x = `self.pc[0]` > > for i in range (0, self.deg+1): > > x = x + "+" +`self.pc[i]`+ self.var + "^" +`i+2` > > return x > > > > def Integrate(p): > > """Input: an instance of a polynommial > > Output: a polynomial that is the integral of the input polynomial > > Side Effects: None""" > > pv=p.var > > pc=[] > > for i in range(0,p.deg): > > I=p.coef[i+1]/float(i+2) > > pc.append(I) > > return Poly2 (v=pv,c=pc) > > > > degree = input('Enter the degree of your polynomial') > > coef=[] > > for i in range (0,degree + 1): > > coefficient = input('Enter the coefficient for x^ %i ? ' %i) > > coef.append(coefficient)#attach the coefficient entered to the end >of > > the > > #list named coef. > > > > s= Poly (c = coef) > > t= Integrate(s) > > # This is some code to test new functions > > > > print "The integral of %s is: \n %s" % (s,t) > > print " " > > > > My problem is that when I run it I get this: > > > > >>>reload(poly1) > > Enter the degree of your polynomial3 > > Enter the coefficient for x^ 0 ? 2 > > Enter the coefficient for x^ 1 ? 5 > > Enter the coefficient for x^ 2 ? 6 > > Enter the coefficient for x^ 3 ? 1 > > The integral of 2+5x^1+6x^2+1x^3 is: > > 2.5+2.5x^2+2.0x^3+0.25x^4 > > > > As you can see, the answer would be right if it weren't for the first >term > > in the polynomial. The first term should be a 2x, so the answer should >look > > like this: 2x^1+2.5x^2+2x^3+0.25x^4. Can anyone help me fix this >problem? > > I think that I need to find a way to have the first term on the list >labeled > > pc, which is 2 to be taken into consideration on the string representing >the > > polynomial. Am I right? If so, How can I accomplish this? Also, I >need to > > find a way so that when the coefficient of x^0 ==0 , the output should > > display a constant c along with the result, so that the answer looks >like > > c+2.5x^2+2x^3+0.23x^4. > > Can anyone guide me in the right direction? All inputs or comments >about my > > program are welcomed and appreciated. > > > > Julieta > > > > _________________________________________________________________ > > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > >-- >Benoit Dupire >Graduate Student >---------------- >I'd like to buy a new Boomerang. How can i get rid of the old one? > > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From bdupire@seatech.fau.edu Thu May 3 05:44:25 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Thu, 03 May 2001 00:44:25 -0400 Subject: [Tutor] attaching the first element in a list to a string References: Message-ID: <3AF0E228.B2D89B02@seatech.fau.edu> Julieta Rangel wrote: > This modification to the program works well in calculating the integral, but > it does not print it out when running the program. When you inputed > poly.s.integrate() followed by print poly.s (In Python Shell), the integral > is printed. What command should we include in the program to make it print > out automatically while running it. If I include these commands in the > actual program, they don't work as they do in Python Shell. s is a Poly object defined in the 'poly' module, and s has a method called 'integrate'. so to access s.integrate() from the interpreter, i input import poly # this executes all the code in poly.py, and therefore creates 's' poly.s.integrate() I do not need the 'poly.' part if i want to refer the object from the module it lives in. read my previous message carefully. The answer to your question was in there... >integrate is now a method of the class Poly >so i can use it like this... > >s= Poly( c=[1 5 6]) # here, we use __init__ >print s # here we use __str__ >s.integrate() # guess what ? I advise you to read the Python tutorial (especially the part dealing with modules) and/or the book called 'Learning Python', so that you can progress more rapidly in Python. Benoit > > > Thanks for your help. > > Julieta > > >From: Benoit Dupire > >To: Julieta Rangel > >CC: tutor@python.org > >Subject: Re: [Tutor] attaching the first element in a list to a string > >Date: Wed, 02 May 2001 21:33:02 -0400 > > > >I modified your program in this way: > > > >class Poly: > > def __init__ ( self, v='x' , c = [0]): > > """__init__(): > > Initializes a polynomial > > Default variable is x > > Default polynomial is zero""" > > self.var = v > > self.coef = c > > self.deg = len(c)-1 > > self.length = len(c) > > def __str__ (self): > > """__str__(): > > Converts a polynomial into a string""" > > x = `self.coef[0]` > > for i in range (1, self.deg+1): > > x = x + "+" +`self.coef[i]` + self.var + "^" + `i` > > return x > > > > > > def integrate(self): > > """Input: an instance of a polynommial > > Output: a polynomial that is the integral of the input polynomial > > Side Effects: None""" > > > > coef=[0] > > self.deg= self.deg +1 > > for i in range(0,self.deg): > > coef.append(self.coef[i]/float(i+1)) > > self.coef= coef > > > > > >degree = input('Enter the degree of your polynomial') > >coef=[] > >for i in range (0,degree + 1): > > coefficient = input('Enter the coefficient for x^ %i ? ' %i) > > coef.append(coefficient) > > > >s= Poly (c = coef) > > > > > > > > > >The result is now the good one: > > >>> reload(poly) > >Enter the degree of your polynomial3 > >Enter the coefficient for x^ 0 ? 2 > >Enter the coefficient for x^ 1 ? 5 > >Enter the coefficient for x^ 2 ? 6 > >Enter the coefficient for x^ 3 ? 1 > > > > >>> poly.s.integrate() > > >>> print poly.s > >0+2.0x^1+2.5x^2+2.0x^3+0.25x^4 > > > > > >What are the difference with your program? > > > >integrate is now a method of the class Poly > >so i can use it like this... > > > >s= Poly( c=[1 5 6]) # here, we use __init__ > >print s # here we use __str__ > >s.integrate() # guess what ? > > > >So the first argument of integrate() is now 'self' (the polynome itself) > >I first increment the degree (because that's the definition of the > >integration > >of a polynom) > >The first coeff should normally be 'k', we need an initial condition to set > >it, > >so for now i put 0 > >next coeff = coeff (degree 0) / (0+1) > >next coeff = coeff (degree 1)/ (1+1) > >etc... > >When i have the new list of coeff, i set it for the current polynom ( > >self.coef= coef) > > > >You can also add your derivation function as a method, and use it like > >s.derivate() > > > >Benoit > > > > > > > > > > > > > > > >Julieta Rangel wrote: > > > > > I have this problem. I'm trying to write a program that calculates the > > > integral of a polynomial. This is what I have so far: > > > > > > import string > > > class Poly: > > > def __init__ ( self, v='x' , c = [0]): > > > """__init__(): > > > Initializes a polynomial > > > Default variable is x > > > Default polynomial is zero""" > > > self.var = v > > > self.coef = c > > > self.deg = len(c)-1 > > > self.length = len(c) > > > def __str__ (self): > > > """__str__(): > > > Converts a polynomial into a string""" > > > x = `self.coef[0]` > > > for i in range (1, self.deg+1): > > > x = x + "+" +`self.coef[i]` + self.var + "^" + `i` > > > return x > > > > > > class Poly2: > > > def __init__ (self, v='x' , c = [0]): > > > """__init__(): > > > Initializes a polynomial > > > Default variable is x > > > Default polynomial is zero""" > > > self.var = v > > > self.pc = c > > > self.deg =len(c)-1 > > > self.length = len(c) > > > def __str__(self): > > > """__str__(): > > > Converts a second polynomial into a string""" > > > x = `self.pc[0]` > > > for i in range (0, self.deg+1): > > > x = x + "+" +`self.pc[i]`+ self.var + "^" +`i+2` > > > return x > > > > > > def Integrate(p): > > > """Input: an instance of a polynommial > > > Output: a polynomial that is the integral of the input polynomial > > > Side Effects: None""" > > > pv=p.var > > > pc=[] > > > for i in range(0,p.deg): > > > I=p.coef[i+1]/float(i+2) > > > pc.append(I) > > > return Poly2 (v=pv,c=pc) > > > > > > degree = input('Enter the degree of your polynomial') > > > coef=[] > > > for i in range (0,degree + 1): > > > coefficient = input('Enter the coefficient for x^ %i ? ' %i) > > > coef.append(coefficient)#attach the coefficient entered to the end > >of > > > the > > > #list named coef. > > > > > > s= Poly (c = coef) > > > t= Integrate(s) > > > # This is some code to test new functions > > > > > > print "The integral of %s is: \n %s" % (s,t) > > > print " " > > > > > > My problem is that when I run it I get this: > > > > > > >>>reload(poly1) > > > Enter the degree of your polynomial3 > > > Enter the coefficient for x^ 0 ? 2 > > > Enter the coefficient for x^ 1 ? 5 > > > Enter the coefficient for x^ 2 ? 6 > > > Enter the coefficient for x^ 3 ? 1 > > > The integral of 2+5x^1+6x^2+1x^3 is: > > > 2.5+2.5x^2+2.0x^3+0.25x^4 > > > > > > As you can see, the answer would be right if it weren't for the first > >term > > > in the polynomial. The first term should be a 2x, so the answer should > >look > > > like this: 2x^1+2.5x^2+2x^3+0.25x^4. Can anyone help me fix this > >problem? > > > I think that I need to find a way to have the first term on the list > >labeled > > > pc, which is 2 to be taken into consideration on the string representing > >the > > > polynomial. Am I right? If so, How can I accomplish this? Also, I > >need to > > > find a way so that when the coefficient of x^0 ==0 , the output should > > > display a constant c along with the result, so that the answer looks > >like > > > c+2.5x^2+2x^3+0.23x^4. > > > Can anyone guide me in the right direction? All inputs or comments > >about my > > > program are welcomed and appreciated. > > > > > > Julieta > > > > > > _________________________________________________________________ > > > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > > > > _______________________________________________ > > > Tutor maillist - Tutor@python.org > > > http://mail.python.org/mailman/listinfo/tutor > > > >-- > >Benoit Dupire > >Graduate Student > >---------------- > >I'd like to buy a new Boomerang. How can i get rid of the old one? > > > > > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From bsass@freenet.edmonton.ab.ca Thu May 3 07:03:25 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Thu, 3 May 2001 00:03:25 -0600 (MDT) Subject: [Tutor] Few simple question. In-Reply-To: <001501c0d37e$424a9ce0$6a01a8c0@com.my> Message-ID: On Thu, 3 May 2001, Mr. Razak wrote: > Actually I'm new in this language, so I really sorry if I'm asking a stupid question. Python itself does not include commands for this sorta thing, but there are a lot of modules to handle whatever type of display you need. > 1). I want to know how to change colour, i mean how to used colour in python language. > > 2). How to used coordinate system, or may be there is a module i can used to help me. For example on the computer screen at a location row=5, column 35, I want to print 'Hello world'. How to do that. > > 3). How to create box and how place it on the computer screen on the desirerable location. Hmmm, are you referring to a text display? If so, you can get python bindings for S-LANG... http://packages.debian.org/unstable/interpreters/python-slang.html ...newt... http://packages.debian.org/unstable/interpreters/python-newt.html ...and ncurses... http://packages.debian.org/unstable/interpreters/pyncurses.html These URLs will take you the Debian package pages, which contain links to the original source tarballs. I'm pointing you to "unstable", refers only to Debian's binary packages, because that should be the most recent source releases; you could use "testing" or "stable", which may get you older releases of the source. S-LANG is good for unix and win32, I'm not sure about the others. ncurses is packaged with the most recent Python release (2.1). HTH - Bruce From julieta_rangel@hotmail.com Thu May 3 07:14:54 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Thu, 03 May 2001 01:14:54 -0500 Subject: [Tutor] attaching the first element in a list to a string Message-ID: I feel like an idiot. Either I'm really tired, or there's something wrong with me. I've been staring at the reply to my question and I still don't see what you are talking about. At the end of the program, am I supposed to write import poly s.integrate() print s ?? I am thankful for all your help. Julieta >From: Benoit Dupire >To: Julieta Rangel >CC: tutor@python.org >Subject: Re: [Tutor] attaching the first element in a list to a string >Date: Thu, 03 May 2001 00:44:25 -0400 > > > >Julieta Rangel wrote: > > > This modification to the program works well in calculating the integral, >but > > it does not print it out when running the program. When you inputed > > poly.s.integrate() followed by print poly.s (In Python Shell), the >integral > > is printed. What command should we include in the program to make it >print > > out automatically while running it. If I include these commands in the > > actual program, they don't work as they do in Python Shell. > >s is a Poly object defined in the 'poly' module, and s has a method called >'integrate'. >so to access s.integrate() from the interpreter, i input >import poly # this executes all the code in poly.py, and >therefore creates 's' >poly.s.integrate() >I do not need the 'poly.' part if i want to refer the object from the >module >it lives in. > > >read my previous message carefully. The answer to your question was in >there... > > >integrate is now a method of the class Poly > >so i can use it like this... > > > >s= Poly( c=[1 5 6]) # here, we use __init__ > >print s # here we use __str__ > >s.integrate() # guess what ? > >I advise you to read the Python tutorial (especially the part dealing with >modules) and/or the book called 'Learning Python', so that you can progress >more >rapidly in Python. > >Benoit > > > > > > > > > Thanks for your help. > > > > Julieta > > > > >From: Benoit Dupire > > >To: Julieta Rangel > > >CC: tutor@python.org > > >Subject: Re: [Tutor] attaching the first element in a list to a string > > >Date: Wed, 02 May 2001 21:33:02 -0400 > > > > > >I modified your program in this way: > > > > > >class Poly: > > > def __init__ ( self, v='x' , c = [0]): > > > """__init__(): > > > Initializes a polynomial > > > Default variable is x > > > Default polynomial is zero""" > > > self.var = v > > > self.coef = c > > > self.deg = len(c)-1 > > > self.length = len(c) > > > def __str__ (self): > > > """__str__(): > > > Converts a polynomial into a string""" > > > x = `self.coef[0]` > > > for i in range (1, self.deg+1): > > > x = x + "+" +`self.coef[i]` + self.var + "^" + `i` > > > return x > > > > > > > > > def integrate(self): > > > """Input: an instance of a polynommial > > > Output: a polynomial that is the integral of the input >polynomial > > > Side Effects: None""" > > > > > > coef=[0] > > > self.deg= self.deg +1 > > > for i in range(0,self.deg): > > > coef.append(self.coef[i]/float(i+1)) > > > self.coef= coef > > > > > > > > >degree = input('Enter the degree of your polynomial') > > >coef=[] > > >for i in range (0,degree + 1): > > > coefficient = input('Enter the coefficient for x^ %i ? ' %i) > > > coef.append(coefficient) > > > > > >s= Poly (c = coef) > > > > > > > > > > > > > > >The result is now the good one: > > > >>> reload(poly) > > >Enter the degree of your polynomial3 > > >Enter the coefficient for x^ 0 ? 2 > > >Enter the coefficient for x^ 1 ? 5 > > >Enter the coefficient for x^ 2 ? 6 > > >Enter the coefficient for x^ 3 ? 1 > > > > > > >>> poly.s.integrate() > > > >>> print poly.s > > >0+2.0x^1+2.5x^2+2.0x^3+0.25x^4 > > > > > > > > >What are the difference with your program? > > > > > >integrate is now a method of the class Poly > > >so i can use it like this... > > > > > >s= Poly( c=[1 5 6]) # here, we use __init__ > > >print s # here we use __str__ > > >s.integrate() # guess what ? > > > > > >So the first argument of integrate() is now 'self' (the polynome >itself) > > >I first increment the degree (because that's the definition of the > > >integration > > >of a polynom) > > >The first coeff should normally be 'k', we need an initial condition to >set > > >it, > > >so for now i put 0 > > >next coeff = coeff (degree 0) / (0+1) > > >next coeff = coeff (degree 1)/ (1+1) > > >etc... > > >When i have the new list of coeff, i set it for the current polynom ( > > >self.coef= coef) > > > > > >You can also add your derivation function as a method, and use it like > > >s.derivate() > > > > > >Benoit > > > > > > > > > > > > > > > > > > > > > > > >Julieta Rangel wrote: > > > > > > > I have this problem. I'm trying to write a program that calculates >the > > > > integral of a polynomial. This is what I have so far: > > > > > > > > import string > > > > class Poly: > > > > def __init__ ( self, v='x' , c = [0]): > > > > """__init__(): > > > > Initializes a polynomial > > > > Default variable is x > > > > Default polynomial is zero""" > > > > self.var = v > > > > self.coef = c > > > > self.deg = len(c)-1 > > > > self.length = len(c) > > > > def __str__ (self): > > > > """__str__(): > > > > Converts a polynomial into a string""" > > > > x = `self.coef[0]` > > > > for i in range (1, self.deg+1): > > > > x = x + "+" +`self.coef[i]` + self.var + "^" + `i` > > > > return x > > > > > > > > class Poly2: > > > > def __init__ (self, v='x' , c = [0]): > > > > """__init__(): > > > > Initializes a polynomial > > > > Default variable is x > > > > Default polynomial is zero""" > > > > self.var = v > > > > self.pc = c > > > > self.deg =len(c)-1 > > > > self.length = len(c) > > > > def __str__(self): > > > > """__str__(): > > > > Converts a second polynomial into a string""" > > > > x = `self.pc[0]` > > > > for i in range (0, self.deg+1): > > > > x = x + "+" +`self.pc[i]`+ self.var + "^" +`i+2` > > > > return x > > > > > > > > def Integrate(p): > > > > """Input: an instance of a polynommial > > > > Output: a polynomial that is the integral of the input >polynomial > > > > Side Effects: None""" > > > > pv=p.var > > > > pc=[] > > > > for i in range(0,p.deg): > > > > I=p.coef[i+1]/float(i+2) > > > > pc.append(I) > > > > return Poly2 (v=pv,c=pc) > > > > > > > > degree = input('Enter the degree of your polynomial') > > > > coef=[] > > > > for i in range (0,degree + 1): > > > > coefficient = input('Enter the coefficient for x^ %i ? ' %i) > > > > coef.append(coefficient)#attach the coefficient entered to the >end > > >of > > > > the > > > > #list named coef. > > > > > > > > s= Poly (c = coef) > > > > t= Integrate(s) > > > > # This is some code to test new functions > > > > > > > > print "The integral of %s is: \n %s" % (s,t) > > > > print " " > > > > > > > > My problem is that when I run it I get this: > > > > > > > > >>>reload(poly1) > > > > Enter the degree of your polynomial3 > > > > Enter the coefficient for x^ 0 ? 2 > > > > Enter the coefficient for x^ 1 ? 5 > > > > Enter the coefficient for x^ 2 ? 6 > > > > Enter the coefficient for x^ 3 ? 1 > > > > The integral of 2+5x^1+6x^2+1x^3 is: > > > > 2.5+2.5x^2+2.0x^3+0.25x^4 > > > > > > > > As you can see, the answer would be right if it weren't for the >first > > >term > > > > in the polynomial. The first term should be a 2x, so the answer >should > > >look > > > > like this: 2x^1+2.5x^2+2x^3+0.25x^4. Can anyone help me fix this > > >problem? > > > > I think that I need to find a way to have the first term on the list > > >labeled > > > > pc, which is 2 to be taken into consideration on the string >representing > > >the > > > > polynomial. Am I right? If so, How can I accomplish this? Also, I > > >need to > > > > find a way so that when the coefficient of x^0 ==0 , the output >should > > > > display a constant c along with the result, so that the answer looks > > >like > > > > c+2.5x^2+2x^3+0.23x^4. > > > > Can anyone guide me in the right direction? All inputs or comments > > >about my > > > > program are welcomed and appreciated. > > > > > > > > Julieta > > > > > > > > _________________________________________________________________ > > > > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > > > > > > _______________________________________________ > > > > Tutor maillist - Tutor@python.org > > > > http://mail.python.org/mailman/listinfo/tutor > > > > > >-- > > >Benoit Dupire > > >Graduate Student > > >---------------- > > >I'd like to buy a new Boomerang. How can i get rid of the old one? > > > > > > > > > > _________________________________________________________________ > > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > >-- >Benoit Dupire >Graduate Student >---------------- >I'd like to buy a new Boomerang. How can i get rid of the old one? > > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From dyoo@hkn.eecs.berkeley.edu Thu May 3 08:57:36 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 3 May 2001 00:57:36 -0700 (PDT) Subject: [Tutor] List problem In-Reply-To: <200105030339_MC2-CEC3-743D@compuserve.com> Message-ID: On Thu, 3 May 2001, Sharriff Aina wrote: > Thanks Mr. Yoo for replying You don't need to call me Mr. Yoo; just Danny is fine for me. (Plus, if you saw me, I'm definitely not a "Mr." quite yet. *grin*) > connection = odbc.odbc('minicms') > cur = connection.cursor() > cur.execute("select * from users where username='%s' and userpwd='%s'" > %(usernamevalue,passwordvalue)) > allrows = cur.fetchall() Ah! But what happens if the user DID misspell either their username or password? In SQL, this means that the result set should be of length 0, because it can't find a user with those qualities. Let's check the documentation: http://python.org/topics/database/DatabaseAPI-2.0.html According to the docs: "fetchall(): Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation. An Error (or subclass) exception is raised if the previous call to executeXXX() did not produce any result set or no call was issued yet." Since we aren't getting an exception out of the system, we'll need to assume that we got an empty result set from the fetchall() instead. It appears that the database found no matches for the query, so it assigned allrows = [] Can you verify this? You might want to add a check like: ### if allrows == []: # output something about "Incorrect password or username. Try # again" else: # now it's ok to start indicing allrows[0]. ### right before you start indexing your allrows; we can't be certain that allrows[0] works until we check to see that we have at least one tuple in the list. Afterwards, it should be ok to check for allrows[0]. Try it out, and see if this is the bug that you're running into. If so, it should be fairly easy to fix. Good luck! From julieta_rangel@hotmail.com Thu May 3 08:59:00 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Thu, 03 May 2001 02:59:00 -0500 Subject: [Tutor] multiplication of polynomials in Python Message-ID: I got the integration and differentiation programs to work. Right now I'm working on multiplication of polynomials. This is what I have so far: class Poly: def __init__ ( self, v=m , c = [0]): """__init__(): Initializes a polynomial variable is m Default polynomial is zero""" self.var = v self.coef = c self.deg = len(c)-1 self.length = len(c) def __str__ (self): """__str__(): Converts a polynomial into a string""" x = `self.coef[0]` for i in range (1, self.deg+1): x = x + "+" +`self.coef[i]` + self.var + "^" + `i` return x def Multiply(self): """Input: two instances of a polynomial Output: a polynomial that is the product of the input polynomials Side Effects: None""" coef=[0] coef2=[0] self.deg = self.deg +1 for i in range(0,self.deg +1): coef.append( m = input('Enter the variable for polynomial1') degree = input('Enter the degree of polynomial 1') coef=[] for i in range (0,degree + 1): coefficient = input('Enter the coefficient for %s \n ^ %i ? ' %(m,i) coef.append(coefficient) m = input('Enter the variable for polynomial 2') degree = input('Enter the degree of polynomial 2') coef2=[] for i in range (0,degree + 1): coefficient = input('Enter the coefficient for %s \n ^ %i ? ' %(m,i) coef.append(coefficient) Am I headed in the right direction? What do you think about what I have so far? I'm trying to come up with the definition of multiply, but I'm stuck. Can anyone help? If you have any comments or suggestions I'm all ears. By the way, thank you everyone for all the help I've received from all of you. Eventhough I still have a VERY LONG way to go, I feel I've learned so much from you. Thank you for sharing your knowledge :) Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From dyoo@hkn.eecs.berkeley.edu Thu May 3 09:09:32 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 3 May 2001 01:09:32 -0700 (PDT) Subject: [Tutor] FieldStorage solution summary In-Reply-To: <200105021238.IAA03791@birds.us.itd.umich.edu> Message-ID: On Wed, 2 May 2001, Lance E Sloan wrote: > Daniel Yoo wrote: > > I'm not sure if dictcat() should have to worry about non-dictionaries; it > > might be better off giving a message that dictcat() needs to take a > > dictonary-like object; otherwise, it might obscure some errors that the > > programmer might forget to check. > > I admit the name of the function might be misleading, but its > primary purpose in life is to convert FieldStorage to dictionary. > Do you mean that I should split this into two functions, one for > converting FieldStorage and the other for concatenating dictionaries? > Or do you mean that I should have the function throw an exception > if it is passed an argument that's not a dictionary or FieldStorage? This is nothing big; I'm just trying to interpret what it means to: dictcat("hello world"). *grin* I think it's a great idea to merge dictionaries and FieldStorages, since they both serve the same purpose of mapping names to things; I just thought it was unusual that one of your test cases stuffs weird things like numbers and strings into the argument list of your dictcat(). From glingl@mail.rg16.asn-wien.ac.at Thu May 3 09:26:35 2001 From: glingl@mail.rg16.asn-wien.ac.at (Gregor Lingl) Date: Thu, 03 May 2001 10:26:35 +0200 Subject: [Tutor] rational number representation in Python References: <5B6B5744C4A@kserver.org> Message-ID: <3AF1163B.C7214FE0@rg16.asn-wien.ac.at> As code for Euclid's algorithm mentioned below you could use:

def gcd(a,b):
    "returns greates common divisor of positive integers a and b"
    while b:
        a, b = b, a%b
    return a

G.L.
 
 

Sheila King schrieb:

On Wed, 02 May 2001 11:58:22 -0500, "Julieta Rangel"
<julieta_rangel@hotmail.com>  wrote about [Tutor] rational number
representation in Python:

:Because my result of
:this division is not an integer, I don't want Python to divide.  I want
:(3/3) to be divided, (4/1) to be divided, but I want (7/2) to be left alone.
:  How can I do this?  Can anyone help?

In comp.lang.python, there has been talk about an experimental number class
that includes rational numbers. (I don't remember the details right now.) You
could possibly use something like that.

Or, it might be instructive to write your own rational number class. For
reducing fractions, like 3/3 or even 9/3, etc... a useful algorithm is called
Euclid's Algorithm. You should be able to find the algorithm in a book on
algorithms fairly easily. It will find the GCF for you, then you can divide it
out of the numerator and denominator.

I would make a test, that whenever the denominator is 1, to just stop printing
it, and let the number be output as 4 instead of 4/1.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

From dyoo@hkn.eecs.berkeley.edu Thu May 3 09:43:14 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 3 May 2001 01:43:14 -0700 (PDT) Subject: [Tutor] bizare Tkinter error In-Reply-To: <200105030339.f433dFQ31313@smtp4.fas.harvard.edu> Message-ID: On Wed, 2 May 2001, Pijus Virketis wrote: > I am writing a class assignment right now, and I have run into a most > peculiar bug. I know where it is, but I have absolutely no clue why it > occurs. Here is the relevant bit of my code: > > class EditFrame: > def __init__(self, master): > ### Set up prompt frame, list frame, edit frame > p_f = l_f = e_f = Frame(master) There's a part here that worries me. p_f, l_f, and e_f all are names for the same Frame; that is, they're just different names for the same object. I'm assuming that you want all three names to refer to distinct things; if so, you'll need this instead: p_f, l_f, e_f = Frame(master), Frame(master), Frame(master) Every time we say "Frame(...)", we make a new Frame, distinct from the others. What you had before appears to only make one frame, so that might be affecting the rest of your code. A similar thing happens when we deal with lists: ### >>> x = y = [1, 2, 3, 4] >>> x [1, 2, 3, 4] >>> y [1, 2, 3, 4] >>> y[4:] = [5, 6, 7] >>> y [1, 2, 3, 4, 5, 6, 7] >>> x [1, 2, 3, 4, 5, 6, 7] ### We explain this by saying that 'x' and 'y' are both directed at the same list; this is a problem if we want to treat the two independently. There are several ways to fix this, but one of the simpler ways of doing this is with the copy module: ### >>> import copy >>> y = [1, 2, 3, 4] >>> x = copy.copy(y) >>> y[4:] = [5, 6, 7] >>> y [1, 2, 3, 4, 5, 6, 7] >>> x [1, 2, 3, 4] ### Unfortunately, copy.copy() isn't smart enough to work for Frames. This reference/object stuff is a somewhat advanced topic, so if it's a little confusing, feel free to ask us more about it, and we'll see if we can cook up a good explanation. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Thu May 3 10:00:20 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 3 May 2001 02:00:20 -0700 (PDT) Subject: [Tutor] List problem In-Reply-To: <200105030437_MC2-CECC-15C9@compuserve.com> Message-ID: On Thu, 3 May 2001, Sharriff Aina wrote: > I tried it ou, heres one variation: > ### code > > if allrows[0] == []: There's a large difference between: if allrows[0] == [] and if allrows == [] It's only three characters, but to Python, it makes a world of difference. Here's an example that might make things clearer: ### >>> l1 = [()] # a list whose first element is an empty tuple >>> l2 = [] # the empty list. >>> l1[0] == [] 0 >>> l2[0] == [] Traceback (innermost last): File "", line 1, in ? IndexError: list index out of range >>> l1 == [] 0 >>> l2 == [] 1 ### Let's make a somewhat silly analogy... hmm... [()]: "a honey jar that contains a deflated balloon." [] : "the empty honey jar." We need to check that allrows isn't an empty honey jar; otherwise, our hands would get sticky for no good reason. (Could you make sure you're selecting the "reply to all" option when you respond to our email? It's usually better to do this because the other tutors can load-balance. Thanks!) From NHYTRO@compuserve.com Thu May 3 13:09:47 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Thu, 3 May 2001 08:09:47 -0400 Subject: [Tutor] If loop not executing completely Message-ID: <200105030810_MC2-CEC9-ABC@compuserve.com> Hi guys, I coded a CGI script with database access: ## code ## #------------------------------------------------------------------------= -- ----- connection =3D odbc.odbc('minicms') cur =3D connection.cursor() cur.execute("select templatetype from userpages where username =3D'%s'" %(usernamevalue)) usertemplate =3D cur.fetchall() cur.close() connection.close() # cleanup and choose css # -------------------------------------------------------------------------= -- --- tempusertemplate =3D usertemplate[0] usertemplate =3D tempusertemplate[0] if usertemplate =3D=3D 'template1': ....htmlhead =3D string.replace(htmlhead, '', templatedir + = 'template1.css') elif usertemplate =3D=3D 'template2': .... htmlhead =3D string.replace(htmlhead, '', templatedir + 'template2.css') .... # and so on # since I=B4m adding images too: ## code if usertemplate =3D=3D 'template1': htmlhead =3D string.replace(htmlhead, '', templatedir + = 'template1.jpg') elif usertemplate =3D=3D 'template2': htmlhead =3D string.replace(htmlhead, '', templatedir + = 'template2.jpg') .... # and so on... I decided to couple both actions together # final code ## tempusertemplate =3D usertemplate[0] usertemplate =3D tempusertemplate[0] if usertemplate =3D=3D 'template1': ....htmlhead =3D string.replace(htmlhead, '', templatedir + = 'template1.css') ....htmlhead =3D string.replace(htmlhead, '', templatedir + = 'template1.jpg') elif usertemplate =3D=3D 'template2': .... htmlhead =3D string.replace(htmlhead, '', templatedir + 'template2.css') .... htmlhead =3D string.replace(htmlhead, '', templatedir + = 'template2.jpg') this promptly causes a "list out of range error" !!??? I switched back to= chugging along the string to be replaced separately. = Sorry to nag you guys Thanks Sharriff From arcege@speakeasy.net Thu May 3 12:59:50 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Thu, 3 May 2001 07:59:50 -0400 (EDT) Subject: [Tutor] Processor Simulator In-Reply-To: <3AF0B4A0.7DC0E1B2@mindless.com> from "Timothy M. Brauch" at May 02, 2001 09:30:08 PM Message-ID: <200105031159.f43BxoV04374@dsl092-074-184.bos1.dsl.speakeasy.net> Timothy M. Brauch wrote > I have a project for my comp-sci class. I have to design a simulator > for a processor, and I've decided to use Python. So, my question is, > does anyone have any suggestions as to how to go about doing this? > Also, I have to write simple files and load them into my simulator. > > My initial thoughts are to create a class with a bunch of function > definitions for different processes. Such as add() and sub() and mul(), > etc. I would try to break different components into separate classes. For example, a class for an ALU, another for external memory (maybe with methods for "read" and "write", especially if you are simulating a RISC type processor ;)), maybe one for a pipeline (later). Then you could have the one "processor" class as the control mechanisms for the components. But above all.. keep it simple. This seems oxymoronic, but as I suggest above, instead of making some big list to simulate possibly megabytes of RAM, just make read/write methods (there will be comparable load/store commands anyway). Don't introduce a cache or special features at first; as attractive as it might be to code, doing so might distract from the "real" features. > I also have to have a display window showing register enteries, which > that I think I can do fairly easily. I was thinking of using the latest > VPython which has a text function (I am doing this mostly because I have > no experience with TK, otherwise I would use it, but right now I don't > have the time to learn it). At first, I would just concentrate on the class(es) for the processor and worry about a user interface later. The project is not a graphical program; keep display in mind while you are designing your program, but keep the focus on the goal. > As for the files, I would use something like readlines and string.split > to break up my commands kept in the external file. I think I can handle > that as well. That sounds fine, especially at first. Also look at string.strip to "nicely" get rid of the whitespace (including the line terminator). Good luck! :) -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From lsloan@umich.edu Thu May 3 13:41:42 2001 From: lsloan@umich.edu (Lance E Sloan) Date: Thu, 03 May 2001 08:41:42 -0400 Subject: [Tutor] Re: Tutor digest, Vol 1 #763 - 13 msgs In-Reply-To: Your message of "Wed, 02 May 2001 23:02:01 EDT." Message-ID: <200105031241.IAA20178@birds.us.itd.umich.edu> "Julieta Rangel" wrote: > problem is representing rational numbers, ie,(7/2). Because my result of > this division is not an integer, I don't want Python to divide. I want > (3/3) to be divided, (4/1) to be divided, but I want (7/2) to be left alone. > How can I do this? Can anyone help? Instead of letting Python divide those numbers, you could store them in a tuple, (numerator, denominator). Of course, reduce the fraction first before storing it in the tuple. I suppose that instead of storing fractions with one as the denominator, (n, 1), in a tuple, you could just store them as the number itself. That's optional. Either way, if you have a function that prints the polynomial, you could make it work with the original or integrated versions, just by checking the type of coefficient. Here's what I would do: if (type(coeff[i]) == types.TupleType): (num, den) = coeff[i] if (den == 1): print num else: print '%d/%d' % (num, den) else: print coeff[i] Of course, making or finding a rational number class, as Ms. King suggested, would probably be best. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Perl & Python CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From bill_tolbert@bigfoot.com Thu May 3 15:13:45 2001 From: bill_tolbert@bigfoot.com (Bill Tolbert) Date: Thu, 3 May 2001 10:13:45 -0400 (EDT) Subject: [Tutor] any serial gurus available? Message-ID: If you folks help me pull this off it'll be a major Python coup for me. Someone at another location is working on this problem in VB and I'd like to nail it down with Python, but I'm a bit stuck at the moment. I need to read data from a small medical device over a serial port (it's a spirometer; measures lung function). I'm using Roger Burnham's Serial package, Python 2.0 on Win98. According to the documentation (yes, I have some!) the "transmission shall be initiated when the PB100 sends a start of header character (0xa5)." I can open the port and ask for the first byte (line 5 below). I indeed receive the header character, so I know something is happening (line 6 prints '0xa5' to stdout). The docs say the device will wait on the PC for an acknowledgement. I believe this is working. Line 9 causes the device to beep. First question: From the docs, "Valid acknowledge signals shall be one byte values in the range of 0x01 to 0xFE." So, is line nine the way to send a valid 0x01? I assume yes (why else would it beep? ) (Side note: The acknowledge value is used to determine the subsequent baud rate. This is a bit confusing. I had to start the conversation with a baud of 4800. The subsequent baud is determined by 52083.3 / acknowledge value. This can range from 52,083.3 (when using 1) to 205 (when using 254). I've tried 1, as below, but also tried 11 which gets me pretty close to 4800. Same behavior.) The device waits 200 milliseconds to adjust the baud rate, then sends either a 1 or a 2. Here's where I get really confused. How do I get the next value? Line 10 begins a for loop. I read 1 byte from the port, looping 10 times. I would expect to see either a 1 or a 2, but instead I usually get a series of 0's. My read of the docs is that it will just dump bytes at this point, then wait on a checksum. I don't think I'm getting anything to calculate a checksum on! My COM1 buffers are set to the minimum, so I don't think I'm losing data in there. Is there something about my read method that isn't correct? Thanks a 0xf4240, Bill ============================== (port setup stuff above...) ... 1 #read some data 2 try: 3 # read the first byte; should be 0xa5 in hex 4 # delivered as an octal 5 header = port.read(1, timed=1) 6 print hex(ord(header[0])) 7 if '0xa5' == hex(ord(header[0])): 8 # send an achnowlegement. now what? 9 port.write(hex(1)) 10 for i in range(1,11): 11 byte = port.read(1, timed=1) 12 blocks.append(byte) 13 print blocks 14 port.close() 15 except: 16 port.close() 17 traceback.print_exc() 18 return None From lsloan@umich.edu Thu May 3 15:22:41 2001 From: lsloan@umich.edu (Lance E Sloan) Date: Thu, 03 May 2001 10:22:41 -0400 Subject: [Tutor] FieldStorage solution summary In-Reply-To: Your message of "Thu, 03 May 2001 01:09:32 PDT." Message-ID: <200105031422.KAA21341@birds.us.itd.umich.edu> Daniel Yoo wrote: > This is nothing big; I'm just trying to interpret what it means to: > > dictcat("hello world"). > > *grin* I think it's a great idea to merge dictionaries and FieldStorages, > since they both serve the same purpose of mapping names to things; I just > thought it was unusual that one of your test cases stuffs weird things > like numbers and strings into the argument list of your dictcat(). Oh, I see what you mean. I wrote the function to operate on FieldStorage and dictionary objects and it just happened that it "ignores" other types. I suppose it would be better to throw an exception when those types are passed to it. I'll probably add that soon, then. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Perl & Python CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From lsloan@umich.edu Thu May 3 16:14:08 2001 From: lsloan@umich.edu (Lance E Sloan) Date: Thu, 03 May 2001 11:14:08 -0400 Subject: [Tutor] #include in DocumentTemplate? Message-ID: <200105031514.LAA21935@birds.us.itd.umich.edu> One of the things that frustrates me about learning Python is the lack of documentation. At least, what I want to know isn't documented or it's hard to find. Perhaps the reason it's so hard to find is that such a feature doesn't exist yet. As I mentioned in one of my previous messages, I've copied the DocumentTemplate module out of Zope to use with some CGIs that I'm writing. It works well and I like it, but I'd like to have one DTML file include another rather than having my program parse several of them in a row. Right now, I have code that looks like this: tmpl = DocumentTemplate.HTMLFile('../templates/header.dtml') print tmpl(title = 'Specify Your Unvailability Date') tmpl = DocumentTemplate.HTMLFile('../templates/unavailcal.dtml') print tmpl(mapping = vars()) tmpl = DocumentTemplate.HTMLFile('../templates/footer.dtml') print tmpl(year = year) What I'd like my code to look like is: tmpl = DocumentTemplate.HTMLFile('../templates/unavailcal.dtml') print tmpl(mapping = vars()) (Just assume I'm doing the right thing with the arguments to tmpl().) And unavailcal.dtml would have something like this: [body stuff here] Is this possible? I've tried it and it doesn't seem to work. Would I have to write a new DTML tag/function to do this for me? Has anybody already done this? -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Perl & Python CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From arcege@speakeasy.net Thu May 3 16:26:28 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Thu, 3 May 2001 11:26:28 -0400 (EDT) Subject: [Tutor] any serial gurus available? In-Reply-To: from "Bill Tolbert" at May 03, 2001 10:13:45 AM Message-ID: <200105031526.f43FQSS04621@dsl092-074-184.bos1.dsl.speakeasy.net> Bill Tolbert wrote > I need to read data from a small medical device over a serial port (it's a > spirometer; measures lung function). I'm using Roger Burnham's Serial > package, Python 2.0 on Win98. > > According to the documentation (yes, I have some!) the "transmission shall > be initiated when the PB100 sends a start of header character (0xa5)." I > can open the port and ask for the first byte (line 5 below). I indeed > receive the header character, so I know something is happening (line 6 > prints '0xa5' to stdout). The docs say the device will wait on the PC for > an acknowledgement. I believe this is working. Line 9 causes the device > to beep. > > First question: From the docs, "Valid acknowledge signals shall be one > byte values in the range of 0x01 to 0xFE." So, is line nine the way to > send a valid 0x01? I assume yes (why else would it beep? ) Below you are sending the hex() of a number, which results in a multi- byte(character) ASCII string, not a single byte binary string to be sent. You might be getting the beep because the first byte written is 48, not 1. The difference is that hex(1) gives a string of three bytes '0'(48), 'x'(120), '1'(49). But the single byte string is '\001'(1). The number in parenthises is the ASCII (ISO-8859-1) value returned by ord(). Python provides a chr() function that creates the ASCII character for a given value. >>> chr(1) # the binary 1, ASCII SOA '\001' >>> chr(32) # space ' ' >>> chr(48) # the ASCII zero numeral, but not the integer 0 '0' > The device waits 200 milliseconds to adjust the baud rate, then sends > either a 1 or a 2. Here's where I get really confused. How do I get the > next value? Line 10 begins a for loop. I read 1 byte from the port, > looping 10 times. I would expect to see either a 1 or a 2, but instead I > usually get a series of 0's. You can sleep for a number of milliseconds by using a float with the "sleep" function in the "time" module. >>> import time >>> sleep_howlong = 0.200 # seconds, or 200 milliseconds >>> time.sleep(sleep_howlong) > My read of the docs is that it will just dump bytes at this point, then > wait on a checksum. I don't think I'm getting anything to calculate a > checksum on! > > My COM1 buffers are set to the minimum, so I don't think I'm losing data > in there. Is there something about my read method that isn't correct? > > Thanks a 0xf4240, > > Bill > ============================== > > (port setup stuff above...) > ... > 1 #read some data > 2 try: > 3 # read the first byte; should be 0xa5 in hex > 4 # delivered as an octal > 5 header = port.read(1, timed=1) > 6 print hex(ord(header[0])) > 7 if '0xa5' == hex(ord(header[0])): #Just test with (use the hex character ('\xa5' with Python 2.1): if '\245' == header[0]: # the octal value of 0xa5 > 8 # send an achnowlegement. now what? > 9 port.write(hex(1)) #Use the binary character instead: port.write(chr(1)) > 10 for i in range(1,11): > 11 byte = port.read(1, timed=1) > 12 blocks.append(byte) #Sleep here, then read ten bytes: time.sleep(0.2) # sleep for 200 milliseconds bytes = port.read(10, timed=1) blocks = list(bytes) > 13 print blocks > 14 port.close() > 15 except: > 16 port.close() > 17 traceback.print_exc() > 18 return None Good luck - I can't test any of this of course, I don't have a device to test it on or the "serial" module you speak of (or the OS). But if it doesn't work, I'm sure someone will correct me. :) -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From lsloan@umich.edu Thu May 3 16:30:50 2001 From: lsloan@umich.edu (Lance E Sloan) Date: Thu, 03 May 2001 11:30:50 -0400 Subject: [Tutor] preventing KeyError from "%" Message-ID: <200105031530.LAA22131@birds.us.itd.umich.edu> I use the "%" operator with strings a lot. One of the things I commonly do is set a dictionary from values submitted via a web page form or read from a database. It's not uncommon that some fields may be empty and there wouldn't be a key for that field in the dictionary. When I use that dictionary with "%" and the format string calls for that key, I get this exception: KeyError: x How can I get "%" to not throw an exception, but instead skip over that key and move on to the next substitution? For example, if I have this: lance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'} monty = {'first': 'Monty', 'last': 'Python'} print '%(first)s %(mi)s %(last)s\n' % lance print '%(first)s %(mi)s %(last)s\n' % monty it would produce: Lance E Sloan Monty Python instead of throwing an exception for the "% monty" line. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Perl & Python CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From lsloan@umich.edu Thu May 3 16:37:43 2001 From: lsloan@umich.edu (Lance E Sloan) Date: Thu, 03 May 2001 11:37:43 -0400 Subject: [Tutor] Sorry! Message-ID: <200105031537.LAA22308@birds.us.itd.umich.edu> When I responded to a previous message, I *meant* to change the subject from "Re: Tutor digest, Vol 1 #763 - 13 msgs" to "Re: rational number representation in Python". I had the new subject in my cut & paste buffer, but I forgot all about it once I started composing my message. I'm very sorry. Of course, it will be me that looks like a foolish net-newbie in the list archives. That'll teach me. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Perl & Python CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From bdupire@seatech.fau.edu Thu May 3 16:42:13 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Thu, 03 May 2001 11:42:13 -0400 Subject: [Tutor] attaching the first element in a list to a string References: Message-ID: <3AF17C55.FC37C45B@seatech.fau.edu> Let's start by the beginning To create a python module, you need to store some code in a .py file. In that .py file, you define some functions, some classes, some objects, some variables, whatever.... ex: # this is toto.py def foo(value): # a function return value +3 a = 2 # a integer variable class Poly: # a class def __init__(): pass # add your code def __str__(): pass # add your code def integrate(): pass # add your code myPoly = Poly() # an object print myPoly # i call a method of the object.. myPoly.integrate() print myPoly _______________ >From the interpreter if i want to use the code which is in toto.py, i input import toto # i need to access toto... toto.a # this accesses variable 'a' in toto, and therefore returns 2 toto.foo(5) # this accesses function 'foo' in toto, and returns 8 print toto.myPoly # when i imported toto, myPoly was created... access it, and print it. In the example i print myPoly either from the interpreter or from the module itself. Notice the difference in the syntax.... >From the interpreter, i have to tell Python in which module the object myPoly lives.... Variables in toto.py lives in the toto namespace... See my comment below Julieta Rangel wrote: > At the end of the program, am I supposed to > write > import poly #### No, don't import the same module within your module. You only need this line if you want to use your module from another module (ie. the interpreter) So skip this line Read the tutorial about Modules and the import function, please! Benoit > > s.integrate() # ok ! > print s ?? # ok > > I am thankful for all your help. > > Julieta > > >From: Benoit Dupire > >To: Julieta Rangel > >CC: tutor@python.org > >Subject: Re: [Tutor] attaching the first element in a list to a string > >Date: Thu, 03 May 2001 00:44:25 -0400 > > > > > > > >Julieta Rangel wrote: > > > > > This modification to the program works well in calculating the integral, > >but > > > it does not print it out when running the program. When you inputed > > > poly.s.integrate() followed by print poly.s (In Python Shell), the > >integral > > > is printed. What command should we include in the program to make it > >print > > > out automatically while running it. If I include these commands in the > > > actual program, they don't work as they do in Python Shell. > > > >s is a Poly object defined in the 'poly' module, and s has a method called > >'integrate'. > >so to access s.integrate() from the interpreter, i input > >import poly # this executes all the code in poly.py, and > >therefore creates 's' > >poly.s.integrate() > >I do not need the 'poly.' part if i want to refer the object from the > >module > >it lives in. > > > > > >read my previous message carefully. The answer to your question was in > >there... > > > > >integrate is now a method of the class Poly > > >so i can use it like this... > > > > > >s= Poly( c=[1 5 6]) # here, we use __init__ > > >print s # here we use __str__ > > >s.integrate() # guess what ? > > > >I advise you to read the Python tutorial (especially the part dealing with > >modules) and/or the book called 'Learning Python', so that you can progress > >more > >rapidly in Python. > > > >Benoit > > > > From arcege@speakeasy.net Thu May 3 16:55:04 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Thu, 3 May 2001 11:55:04 -0400 (EDT) Subject: [Tutor] #include in DocumentTemplate? In-Reply-To: <200105031514.LAA21935@birds.us.itd.umich.edu> from "Lance E Sloan" at May 03, 2001 11:14:08 AM Message-ID: <200105031555.f43Ft5O04662@dsl092-074-184.bos1.dsl.speakeasy.net> Lance E Sloan wrote > > > One of the things that frustrates me about learning Python is the lack > of documentation. At least, what I want to know isn't documented or > it's hard to find. Perhaps the reason it's so hard to find is that > such a feature doesn't exist yet. > > As I mentioned in one of my previous messages, I've copied the > DocumentTemplate module out of Zope to use with some CGIs that I'm > writing. It works well and I like it, but I'd like to have one DTML > file include another rather than having my program parse several of > them in a row. This isn't a Zope list, there is one there where you can probably get a much better answer. There's plenty of documentation on Zope and its components; have you looked at ? > Right now, I have code that looks like this: > > ^Itmpl = DocumentTemplate.HTMLFile('../templates/header.dtml') > ^Iprint tmpl(title = 'Specify Your Unvailability Date') > > ^Itmpl = DocumentTemplate.HTMLFile('../templates/unavailcal.dtml') > ^Iprint tmpl(mapping = vars()) > > ^Itmpl = DocumentTemplate.HTMLFile('../templates/footer.dtml') > ^Iprint tmpl(year = year) > > What I'd like my code to look like is: > > ^Itmpl = DocumentTemplate.HTMLFile('../templates/unavailcal.dtml') > ^Iprint tmpl(mapping = vars()) > > (Just assume I'm doing the right thing with the arguments to tmpl().) > And unavailcal.dtml would have something like this: > > ^I > > ^I[body stuff here] > > ^I > > Is this possible? I've tried it and it doesn't seem to work. Would I > have to write a new DTML tag/function to do this for me? Has anybody > already done this? I'd say, off hand, that DTML is not going to process standard server-side includes. That would be up to whatever server you have that handles them. But me-thinks that it would definately be after the DTML is processes by Python. The DT_HTML.HTML class will handle some of its own server-side includes. It may be that you are to make a subclass to make your own handling of these. I don't know how many ppl here are Zope-ites; it might be better for you to repost your question on the zope mailing list there is also an IRC channel (according to the website): #zope on the server irc.zope.net:6667 (seemingly an Open Source IRC network, there is even a #python channel). -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From scarblac@pino.selwerd.nl Thu May 3 16:53:11 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Thu, 3 May 2001 17:53:11 +0200 Subject: [Tutor] preventing KeyError from "%" In-Reply-To: <200105031530.LAA22131@birds.us.itd.umich.edu>; from lsloan@umich.edu on Thu, May 03, 2001 at 11:30:50AM -0400 References: <200105031530.LAA22131@birds.us.itd.umich.edu> Message-ID: <20010503175311.A17555@pino.selwerd.nl> On 0, Lance E Sloan wrote: > I use the "%" operator with strings a lot. One of the things I > commonly do is set a dictionary from values submitted via a web page > form or read from a database. It's not uncommon that some fields may > be empty and there wouldn't be a key for that field in the dictionary. > When I use that dictionary with "%" and the format string calls for > that key, I get this exception: > > KeyError: x > > How can I get "%" to not throw an exception, but instead skip over that > key and move on to the next substitution? For example, if I have > this: > > lance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'} > monty = {'first': 'Monty', 'last': 'Python'} > > print '%(first)s %(mi)s %(last)s\n' % lance > print '%(first)s %(mi)s %(last)s\n' % monty > > it would produce: > > Lance E Sloan > Monty Python > > instead of throwing an exception for the "% monty" line. You can't do that with the standard dictionary, so you have to roll your own, inherited from UserDict, i.e.: from UserDict import UserDict class MyDict(UserDict): def __getitem__(self, arg): # Returns "" for any arg that's not in the underlying dictionary if self.data.has_key(arg): return self.data[arg] else: return "" print '%(first)s %(mi)s %(last)s\n' % MyDict(lance) -- Remco Gerlich From bdupire@seatech.fau.edu Thu May 3 17:00:26 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Thu, 03 May 2001 12:00:26 -0400 Subject: [Tutor] preventing KeyError from "%" References: <200105031530.LAA22131@birds.us.itd.umich.edu> Message-ID: <3AF1809A.7120D77E@seatech.fau.edu> if don't know if it's what you are looking for, but the following wouldn't do what you want ? monty = {'first': 'Monty', 'last': 'Python'} for key in ['first', 'mi', 'last']" if not lance.has_key(key): monty[key]='' print '%(first)s %(mi)s %(last)s\n' % monty It just add the keys that don't exist... Benoit Lance E Sloan wrote: > I use the "%" operator with strings a lot. One of the things I > commonly do is set a dictionary from values submitted via a web page > form or read from a database. It's not uncommon that some fields may > be empty and there wouldn't be a key for that field in the dictionary. > When I use that dictionary with "%" and the format string calls for > that key, I get this exception: > > KeyError: x > > How can I get "%" to not throw an exception, but instead skip over that > key and move on to the next substitution? For example, if I have > this: > > lance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'} > monty = {'first': 'Monty', 'last': 'Python'} > > print '%(first)s %(mi)s %(last)s\n' % lance > print '%(first)s %(mi)s %(last)s\n' % monty > > it would produce: > > Lance E Sloan > Monty Python > > instead of throwing an exception for the "% monty" line. > > -- > Lance E Sloan > Web Services, Univ. of Michigan: Full-service Web and database design, > development, and hosting. Specializing in Perl & Python CGIs. > http://websvcs.itd.umich.edu/ - "Putting U on the Web" > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From bdupire@seatech.fau.edu Thu May 3 17:04:06 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Thu, 03 May 2001 12:04:06 -0400 Subject: [Tutor] preventing KeyError from "%" References: <200105031530.LAA22131@birds.us.itd.umich.edu> Message-ID: <3AF18176.B705084C@seatech.fau.edu> Oh oh oh ! I ve just seen Remco's answer (which is far better than mine, because field names are not hard-coded )... The idea is about the same though... Benoit. Lance E Sloan wrote: > I use the "%" operator with strings a lot. One of the things I > commonly do is set a dictionary from values submitted via a web page > form or read from a database. It's not uncommon that some fields may > be empty and there wouldn't be a key for that field in the dictionary. > When I use that dictionary with "%" and the format string calls for > that key, I get this exception: > > KeyError: x > > How can I get "%" to not throw an exception, but instead skip over that > key and move on to the next substitution? For example, if I have > this: > > lance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'} > monty = {'first': 'Monty', 'last': 'Python'} > > print '%(first)s %(mi)s %(last)s\n' % lance > print '%(first)s %(mi)s %(last)s\n' % monty > > it would produce: > > Lance E Sloan > Monty Python > > instead of throwing an exception for the "% monty" line. > > -- > Lance E Sloan > Web Services, Univ. of Michigan: Full-service Web and database design, > development, and hosting. Specializing in Perl & Python CGIs. > http://websvcs.itd.umich.edu/ - "Putting U on the Web" > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From DOUGS@oceanic.com Thu May 3 17:07:04 2001 From: DOUGS@oceanic.com (Doug Stanfield) Date: Thu, 3 May 2001 06:07:04 -1000 Subject: [Tutor] preventing KeyError from "%" Message-ID: <8457258D741DD411BD3D0050DA62365907A7CD@huina.oceanic.com> [Lance E Sloan asked:] > I use the "%" operator with strings a lot. One of the things I > commonly do is set a dictionary from values submitted via a web page > form or read from a database. It's not uncommon that some fields may > be empty and there wouldn't be a key for that field in the dictionary. > When I use that dictionary with "%" and the format string calls for > that key, I get this exception: > > KeyError: x > > How can I get "%" to not throw an exception, but instead skip > over that > key and move on to the next substitution? Look into the 'update' method of dictionaries. As an example, you might start with a template dictionary: Python 1.5.2 (#1, Apr 18 1999, 16:03:16) [GCC pgcc-2.91.60 19981201 (egcs-1.1.1 on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> temp_dict = {'first': '', 'mi': '', 'last': ''} >>> lance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'} >>> temp_dict.update(lance) >>> temp_dict {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'} >>> temp_dict = {'first': '', 'mi': '', 'last': ''} >>> monty = {'first': 'Monty', 'last': 'Python'} >>> temp_dict.update(monty) >>> temp_dict {'first': 'Monty', 'last': 'Python', 'mi': ''} >>> HTH -Doug- From ium@micromuse.com Thu May 3 17:06:26 2001 From: ium@micromuse.com (ibraheem umaru-mohammed) Date: Thu, 3 May 2001 17:06:26 +0100 Subject: [Tutor] Sorry! In-Reply-To: <200105031537.LAA22308@birds.us.itd.umich.edu>; from lsloan@umich.edu on Thu, May 03, 2001 at 11:37:43AM -0400 References: <200105031537.LAA22308@birds.us.itd.umich.edu> Message-ID: <20010503170626.B9282@ignoramus> Hi, [Lance E Sloan wrote...] -| -| When I responded to a previous message, I *meant* to change the subject -| from "Re: Tutor digest, Vol 1 #763 - 13 msgs" to "Re: rational number -| representation in Python". I had the new subject in my cut & paste -| buffer, but I forgot all about it once I started composing my message. -| I don't know what mail client or operating system you use, but if you are using *nix, then you might find the formail command useful with digested messages. man formail For example, under mutt, I can do the following in the command prompt when the digest file is selected in my inbox: :formail +1 -ds >> mailbox this will un-digest the message from a single one, to multiple, of which you can reply to each individually as opposed to changing any of the subject headers, and inadvertently breaking any message threads. Hope that helps, --ibs. -- One meets his destiny often on the road he takes to avoid it. From arcege@speakeasy.net Thu May 3 17:08:18 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Thu, 3 May 2001 12:08:18 -0400 (EDT) Subject: [Tutor] preventing KeyError from "%" In-Reply-To: <200105031530.LAA22131@birds.us.itd.umich.edu> from "Lance E Sloan" at May 03, 2001 11:30:50 AM Message-ID: <200105031608.f43G8IC04693@dsl092-074-184.bos1.dsl.speakeasy.net> Lance E Sloan wrote > > > I use the "%" operator with strings a lot. One of the things I > commonly do is set a dictionary from values submitted via a web page > form or read from a database. It's not uncommon that some fields may > be empty and there wouldn't be a key for that field in the dictionary. > When I use that dictionary with "%" and the format string calls for > that key, I get this exception: > > ^IKeyError: x > > How can I get "%" to not throw an exception, but instead skip over that > key and move on to the next substitution? For example, if I have > this: > > ^Ilance = {'first': 'Lance', 'mi': 'E', 'last': 'Sloan'} > ^Imonty = {'first': 'Monty', 'last': 'Python'} > > ^Iprint '%(first)s %(mi)s %(last)s\n' % lance > ^Iprint '%(first)s %(mi)s %(last)s\n' % monty > > it would produce: > > ^ILance E Sloan > ^IMonty Python > > instead of throwing an exception for the "% monty" line. Sorry, but no. All values must exist in the dictionary. >From the Python Library Reference Manual: If the right argument is a dictionary (or any kind of mapping), then the formats in the string _must_ have a parenthesized key into that dictionary inserted immediately after the "%" character, and each format formats the corresponding entry from the mapping. You could make sure that all values are an empty string at first. Create a dictionary with empty strings first, and populate it with the values afterward. Or go thru the dictionary and find the missing fields and populate the dictionary that way. -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From lsloan@umich.edu Thu May 3 17:11:57 2001 From: lsloan@umich.edu (Lance E Sloan) Date: Thu, 03 May 2001 12:11:57 -0400 Subject: [Tutor] preventing KeyError from "%" In-Reply-To: Your message of "Thu, 03 May 2001 17:53:11 +0200." <20010503175311.A17555@pino.selwerd.nl> Message-ID: <200105031611.MAA22705@birds.us.itd.umich.edu> Remco Gerlich wrote: > You can't do that with the standard dictionary, so you have to roll your > own, inherited from UserDict, i.e.: Thank you very much. After I sent my question to the list, I realized that KeyError is an exception thrown by the dictionary object and not necessarily a "%" problem. I thought the solution might be something like that, but I didn't know quite how to do it. -- Lance E Sloan Web Services, Univ. of Michigan: Full-service Web and database design, development, and hosting. Specializing in Perl & Python CGIs. http://websvcs.itd.umich.edu/ - "Putting U on the Web" From deirdre@deirdre.net Thu May 3 17:23:58 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Thu, 3 May 2001 09:23:58 -0700 Subject: [Tutor] If loop not executing completely In-Reply-To: <200105030810_MC2-CEC9-ABC@compuserve.com> References: <200105030810_MC2-CEC9-ABC@compuserve.com> Message-ID: >this promptly causes a "list out of range error" !!??? I switched back to >chugging along the string to be replaced separately. Can you post the *actual* traceback? -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From randrews@planhouse.com Thu May 3 18:24:39 2001 From: randrews@planhouse.com (Rob Andrews) Date: Thu, 3 May 2001 12:24:39 -0500 Subject: [Tutor] Guido and ESR post to Useless Python Message-ID: <000a01c0d3f5$ef481220$de00a8c0@planhouse5> I'll get the code posted tonight, but wanted to go ahead and spread a little glee. Guido van Rossum and Eric S. Raymond (Open Source programming deity) have both submitted code to be posted on Useless Python today. Eric S. Raymond's script reports on upgrades needed to use a particular kernel, Guido van Rossum's scripts analyze access_log files and ftp logfiles, respectively. Delighted, Rob Useless Python http://www.lowerstandard.com/python/pythonsource.html From julieta_rangel@hotmail.com Thu May 3 18:37:35 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Thu, 03 May 2001 12:37:35 -0500 Subject: [Tutor] inserting items into a list Message-ID: I'm trying to come up with a definition for multiplication of polynomials. Say I want to multiply (2 + 3x + x^2 + 2x^3) times (1+0x+2x^2), so I created two lists of coefficients. List 1 =[2,3,1,2] and list 2= [1,0,2]. To multiply these two I need to take each element from list 1 and multiply it by all of the elements of list 2, and create a new list for each result. For example, by multiplying the first element of list 1 by all of the elemens of list 2 I would get [2,0,4], from the second #, I would get [3,0,6], then [1,0,2] and finally [2,0,4]. I need to find a way to insert 3 zeroes at the end of list [2,0,4]; 1 zero at the beginning and two at the end of [3,0,6]; 2 zeroes a the beginning and one at the end of [1,0,2], and finally 3 zeroes at the beginning of [2,0,4]. This way the new lists would look like: [2,0,4,0,0,0] [0,3,0,6,0,0] [0,0,1,0,2,0] [0,0,0,2,0,4] and it would be just a matter of adding those lists to figure out the result: 2 + 3x + 5x^2 + 8x^3 + 2x^4 + 4x^5. As you can see from the subject, my problem is inserting those zeroes at the specific locations. Can you help me? Julieta If you notice, there is a little pattern _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From deirdre@deirdre.net Thu May 3 18:49:07 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Thu, 3 May 2001 10:49:07 -0700 Subject: [Tutor] Guido and ESR post to Useless Python In-Reply-To: <000a01c0d3f5$ef481220$de00a8c0@planhouse5> References: <000a01c0d3f5$ef481220$de00a8c0@planhouse5> Message-ID: >I'll get the code posted tonight, but wanted to go ahead and spread a little >glee. Guido van Rossum and Eric S. Raymond (Open Source programming deity) >have both submitted code to be posted on Useless Python today. Woohoo! You've hit the major league now. I think you ought to write Larry Wall and Rasmus Lerdorf and see if they have any potential entries. :) >Eric S. Raymond's script reports on upgrades needed to use a particular >kernel, Guido van Rossum's scripts analyze access_log files and ftp >logfiles, respectively. -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From gibbs05@flash.net Thu May 3 18:53:46 2001 From: gibbs05@flash.net (Harry Kattz) Date: Thu, 3 May 2001 12:53:46 -0500 Subject: [Tutor] starting a tkinter window maximized References: <200105022143.f42LhKo22431@pop.nsacom.net> Message-ID: <00f501c0d3fa$45da6800$09dd3040@gibbs05> > The subject pretty much says it all! How does one tell a tkinter window to > start maximized in windows or X? I didn't see an answer to this one yet, so I'll give it a shot. wm_state('zoomed') should maximize on Windows. For example: >>> import os >>> from Tkinter import * >>> class MaxWin(Tk): ... def __init__(self): ... Tk.__init__(self) ... Label(self, text = "Test Zoom").pack() ... if os.name == 'nt': ... self.wm_state('zoomed') ... >>> test = MaxWin() >>> test.mainloop() This produced a full size window with a label. Zoomed isn't valid for Unix so, as far a I know, you'd have to calculate screen width & height and set your window size accordingly. I don't suggest you do this though, because I've had some Unix users tell me maximizing an app is very rude. Good luck, Sam From randrews@planhouse.com Thu May 3 18:58:51 2001 From: randrews@planhouse.com (Rob Andrews) Date: Thu, 3 May 2001 12:58:51 -0500 Subject: [Tutor] Guido and ESR post to Useless Python In-Reply-To: Message-ID: <000b01c0d3fa$b6e639c0$de00a8c0@planhouse5> hehe... I've already thought of asking Larry Wall, who just might do it on general principle. This all gives me a good excuse to tighten up the site again this weekend, breaking it up into several smaller pages. Any Tutor folk who would like to make suggestions on how the site *should* be are welcome to email me (privately if it's not appropriate on the list). Rob -----Original Message----- From: Deirdre Saoirse Moen [mailto:deirdre@deirdre.net] Sent: Thursday, May 03, 2001 12:49 PM To: randrews@planhouse.com; tutor@python.org Subject: Re: [Tutor] Guido and ESR post to Useless Python >I'll get the code posted tonight, but wanted to go ahead and spread a little >glee. Guido van Rossum and Eric S. Raymond (Open Source programming deity) >have both submitted code to be posted on Useless Python today. Woohoo! You've hit the major league now. I think you ought to write Larry Wall and Rasmus Lerdorf and see if they have any potential entries. :) >Eric S. Raymond's script reports on upgrades needed to use a particular >kernel, Guido van Rossum's scripts analyze access_log files and ftp >logfiles, respectively. -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From vlindberg@verio.net Thu May 3 20:44:13 2001 From: vlindberg@verio.net (VanL) Date: Thu, 03 May 2001 13:44:13 -0600 Subject: [Tutor] Moving email redux, and scripting browsers Message-ID: <3AF1B50D.D013E000@verio.net> Hello, In mentioning my moving email problem yesterday, I neglected to mention that there is a web-based interface ... and after some work, it appears that it will probably be necessary to use the web interface to move the email from the different "folders" to the inbox, where I can pop it off using poplib. Considering I still want to script this thing, though, I want to script a browser. I figure that I can do this one of two ways: either using com with ie in windows, or using the python bindings to konqueror in linux or FreeBSD. Has anyone had any experience with any of these? Can anyone recommend one of these options (or even another? Does anyone know where I could get more information? What I would want to do is parse and submit several forms, including a login form. Thanks, VanL From kromag@nsacom.net Fri May 4 00:08:24 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Thu, 3 May 2001 16:08:24 -0700 (PDT) Subject: [Tutor] Cackling with Maniac Laughter (was: starting a tkinter window maximized) Message-ID: <200105032308.f43N8Oo06988@pop.nsacom.net> > wm_state('zoomed') should maximize on Windows. For example: > > >>> import os > >>> from Tkinter import * > >>> class MaxWin(Tk): > ... def __init__(self): > ... Tk.__init__(self) > ... Label(self, text = "Test Zoom").pack() > ... if os.name == 'nt': > ... self.wm_state('zoomed') > ... > >>> test = MaxWin() > >>> test.mainloop() > > This produced a full size window with a label. Thanks! I'll try it! The only problem I can see is that I already have a class declared to put in a ScrolledCanvas (maybe I should have mentioned that. Sorry.) To wit: #!/usr/bin/python from Tkinter import * class ScrolledCanvas(Frame): def __init__(self, parent=None, color='white'): Frame.__init__(self, parent) self.pack(expand=YES, fill=BOTH) self.photo=PhotoImage (file="\windows\desktop\screensaver\wacky3.gif") canv=Canvas(self, bg=color, relief=SUNKEN) canv.config(width=1000, height=700) canv.config(scrollregion=(0,0, 300, 1000)) canv.create_image(10,10, image=self.photo, anchor=NW) sbar=Scrollbar(self) sbar.config(command=canv.yview) canv.config(yscrollcommand=sbar.set) sbar.pack(side=RIGHT, fill=Y) canv.pack(side=LEFT, expand=YES, fill=BOTH) Button(text="quit", command=self.quit).pack(fill=X) if __name__ == '__main__':ScrolledCanvas().mainloop() > I don't suggest > you do this though, because I've had some Unix users tell me maximizing an > app is very rude. Good heavens yes it is rude. Unfortunately I am stuck with Win9x for this particular experiment! :-) What I am trying to do is pop up a window as a screen saverish app that displays information rather than a cute bouncing whatsis. I 'compiled' the program with py2exe (a wonderful program!) then switched it's extention to .scr. Walla! A badly-behaved screensaver! I cackled with Maniac Laughter as as my little script popped up after 60 seconds! :-) Now all I have to do is come up with code that will only allow one instance of the program to run at a time (I know I saw something to the effect in one of my Python books, so no one answer this till I give up! ;-) Of the five parts of the windows screensaver API, I need: 1. provide a description of itself 2. distinguish between active mode and configuration mode 3. disallow multiple copies of itself to run I just got "Python Programming for Win32", so I hope the answers lie therin. (If I can keep from playing with the cool accounting examples he is starting us out with. I never thought that stuff would be this interesting....) Thanks so much! d > > Good luck, > Sam > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From xinch@bigfoot.com Thu May 3 21:59:09 2001 From: xinch@bigfoot.com (KIU Shueng Chuan) Date: Thu, 3 May 2001 22:59:09 +0200 Subject: [Tutor] multiplication of polynomials in Python In-Reply-To: Message-ID: <3AF1E2BD.30573.A752372@localhost> On 3 May 2001, at 2:59, Julieta Rangel wrote: > I got the integration and differentiation programs to work. Right now I'm > working on multiplication of polynomials. This is what I have so far: How about doing addition first? an example: (ax^2 + bx + c) * ( dx^2 + ex + f) = ax^2 * (dx^2 + ex + f) + bx * (dx^2 + ex + f) + c * (dx^2 + ex + f) Take the first polynomial, split into its separate components and multiply each component into the second polynomial. Then at the end add them up. using your representation: ax^2 * (dx^2 + ex + f) would be the multiplication between [0,0,a] and [f,e,d] which equals [0,0,a*f, a*e, a*d] From xinch@free.fr Thu May 3 22:12:56 2001 From: xinch@free.fr (KIU Shueng Chuan) Date: Thu, 3 May 2001 23:12:56 +0200 Subject: (Fwd) Re: [Tutor] multiplication of polynomials in Python Message-ID: <3AF1E5F8.25886.A81C23F@localhost> (I sent this previously with the wrong email addx, apologies if two copies get sent) On 3 May 2001, at 2:59, Julieta Rangel wrote: > I got the integration and differentiation programs to work. Right now I'm > working on multiplication of polynomials. This is what I have so far: How about doing addition first? an example: (ax^2 + bx + c) * ( dx^2 + ex + f) = ax^2 * (dx^2 + ex + f) + bx * (dx^2 + ex + f) + c * (dx^2 + ex + f) Take the first polynomial, split into its separate components and multiply each component into the second polynomial. Then at the end add them up. using your representation: ax^2 * (dx^2 + ex + f) would be the multiplication between [0,0,a] and [f,e,d] which equals [0,0,a*f, a*e, a*d] From arcege@speakeasy.net Thu May 3 22:31:10 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Thu, 3 May 2001 17:31:10 -0400 (EDT) Subject: [Tutor] Cackling with Maniac Laughter (was: starting a tkinter window maximized) In-Reply-To: <200105032308.f43N8Oo06988@pop.nsacom.net> from "kromag@nsacom.net" at May 03, 2001 04:08:24 PM Message-ID: <200105032131.f43LVAg05015@dsl092-074-184.bos1.dsl.speakeasy.net> kromag@nsacom.net wrote [snipped] > Good heavens yes it is rude. Unfortunately I am stuck with Win9x for this > particular experiment! :-) > > What I am trying to do is pop up a window as a screen saverish app that > displays information rather than a cute bouncing whatsis. I 'compiled' the > program with py2exe (a wonderful program!) then switched it's extention > to .scr. Walla! A badly-behaved screensaver! > > I cackled with Maniac Laughter as as my little script popped up after 60 > seconds! :-) > > Now all I have to do is come up with code that will only allow one instance > of the program to run at a time (I know I saw something to the effect in one > of my Python books, so no one answer this till I give up! ;-) > > Of the five parts of the windows screensaver API, I need: > > 1. provide a description of itself > 2. distinguish between active mode and configuration mode > 3. disallow multiple copies of itself to run > > I just got "Python Programming for Win32", so I hope the answers lie therin. > (If I can keep from playing with the cool accounting examples he is starting > us out with. I never thought that stuff would be this interesting....) You might also want to get rid of the window manager's decorations with wm_transient() and making it on top (focus_set, grab_set_global, tkraise). Just provide a way of making a way of stopping it (moving mouse, key press, etc.). -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From iamgod@st.jyu.fi Thu May 3 22:36:33 2001 From: iamgod@st.jyu.fi (Risto Peranen) Date: Fri, 4 May 2001 00:36:33 +0300 (EEST) Subject: [Tutor] Python and web-pages? In-Reply-To: Message-ID: I wrote before 'can you make dynamic web-pages with python?' and I realized my question was terrible wrong. What MENT was something like 'How do you make web-service for your page?' I am working on game-project and I want to make web pages, where my co-coders can make AI-scripts with graphical tools. (It something dull and boring, I don't bother you with details.) I want make python script that receives data from page, and translate it into form the game-AI-gore can use it. here is drawing: (page will be written in Java ) _________________ | My web pages |----> text_file for py-script |_______________| / / / / ________/_____ ____________ | my py-script|->binary file for gore -> | AI-gore | |_____________| |__________| Sure I could do ALL task in Java but it's not the tool I'm looking for. Prosessing of the text-files is (too) easy to do with python. Sure I could build text-prosessor straithly to AI-gore, but the AI-scripts would have to be prosessed every time when starting then game which would cost lots and lots of valuable time. (Besides gore is huge enough without any decorations) Can someone help me? That all folks. Good night Risto Peranen From sheila@thinkspot.net Fri May 4 00:27:00 2001 From: sheila@thinkspot.net (Sheila King) Date: Thu, 03 May 2001 16:27:00 -0700 Subject: [Tutor] inserting items into a list In-Reply-To: References: Message-ID: <6245C1B04BC@kserver.org> Julieta, I really wouldn't go about this, quite that way. It isn't necessary to generate separate lists, filled with zeros, and then sum those to get your result. I will repeat here, something that I posted a few days back. Perhaps you missed it, because there was so much new stuff for you to learn at that point. Posted on April 29th: SK> In order to multiply two polynomials, you would need to take each SK> coefficient in the one list and multiply it be each coefficient in the SK> other list. SK> SK> So, your suggested problem SK> (2x^3 + x^2 + 3x + 2) * (x^2 + 1) SK> SK> might look like this: SK> p1 = [2, 3, 1, 2] SK> p2 = [1, 0, 1] SK> SK> I would note, that since you are multiplying a 3rd degree polynomial by a SK> 2nd degree one, that your result should be fifth degree. You could find SK> this out by doing len(p1)-1 added to len(p2)-1 then create a new SK> list to store the results of your multiplication. Give it length of SK> 5 and initialize all spots to zero. Let's call this new list for the SK> result, p3. SK> SK> Now create a loop to go through each element of p1. SK> Start with p1[0] and multiply it by p2[0] and add the result to p3[0]. SK> Now multiply p1[0] with p2[1] and add the result to p3[1]. SK> Now multiply p1[0] with p2[2] and add the result to p3[2]. SK> SK> All done with p1[0]. Now the loop moves to p1[1]. SK> Multiply p1[1] with p2[0] and add the result to p3[1]. SK> Now multiply p1[1] with p2[1] and add the result to p3[2]. SK> Now multiply p1[1] with p2[2] and add the result to p3[3]. SK> SK> Note, that the indices indicate the exponent on your variable. So, p1[1] SK> is an x^1 coefficient and p2[2] is an x^2 coefficient, so the result needs SK> to be an x^3 coefficient, so add that result to p3[3]. SK> SK> Proceed on to p1[2] and p1[3] in the same manner. So, you have a loop on SK> p1, and inside that loop is another loop that iterates over all the SK> indices in p2. SK> SK> I hope this is helpful. If what I wrote above isn't clear, please ask and I will try to explain it better. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ On Thu, 03 May 2001 12:37:35 -0500, "Julieta Rangel" wrote about [Tutor] inserting items into a list: :I'm trying to come up with a definition for multiplication of polynomials. :Say I want to multiply (2 + 3x + x^2 + 2x^3) times (1+0x+2x^2), so I created :two lists of coefficients. List 1 =[2,3,1,2] and list 2= [1,0,2]. To :multiply these two I need to take each element from list 1 and multiply it :by all of the elements of list 2, and create a new list for each result. :For example, by multiplying the first element of list 1 by all of the :elemens of list 2 I would get [2,0,4], from the second #, I would get :[3,0,6], then [1,0,2] and finally [2,0,4]. I need to find a way to insert 3 :zeroes at the end of list [2,0,4]; 1 zero at the beginning and two at the :end of [3,0,6]; 2 zeroes a the beginning and one at the end of [1,0,2], and :finally 3 zeroes at the beginning of [2,0,4]. This way the new lists would :look like: : :[2,0,4,0,0,0] :[0,3,0,6,0,0] :[0,0,1,0,2,0] :[0,0,0,2,0,4] : :and it would be just a matter of adding those lists to figure out the :result: 2 + 3x + 5x^2 + 8x^3 + 2x^4 + 4x^5. As you can see from the :subject, my problem is inserting those zeroes at the specific locations. :Can you help me? : :Julieta : :If you notice, there is a little pattern :_________________________________________________________________ :Get your FREE download of MSN Explorer at http://explorer.msn.com : : :_______________________________________________ :Tutor maillist - Tutor@python.org :http://mail.python.org/mailman/listinfo/tutor From julieta_rangel@hotmail.com Fri May 4 00:27:25 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Thu, 03 May 2001 18:27:25 -0500 Subject: [Tutor] range Message-ID: I have the following program but when I run it it only runs half-ways. It displays a message of out of range. Can you tell me what I'm doing wrong? class Poly: def __init__ ( self, v='x' , c = [0]): """__init__(): Initializes a polynomial Default variable is x Default polynomial is zero""" self.var = v self.coef = c self.deg = len(c)-1 self.length = len(c) def __str__ (self): """__str__(): Converts a polynomial into a string""" x = `self.coef[0]` for i in range (1,self.deg+1): x = x + "+" +`self.coef[i]` + self.var + "^" + `i` return x def integrate(self): """Input: an instance of a polynommial Output: a polynomial that is the integral of the input polynomial Side Effects: None""" coef=[0] self.deg= self.deg +1 for i in range(0,self.deg): coef.append(self.coef[i]/float(i+1)) self.coef= coef def Derivative(self): """Input: an instance of a polynomial Output: a polynomial that is the derivative of the input polynomial side Effects: None""" coef=[1] self.deg= self.deg +1 if self.deg==0: coef=[0] else: for i in range(0,self.deg-1): coef.append((i+1)*self.coef[i+1]) self.coef= coef degree = input('Enter the degree of your polynomial') coef=[] for i in range (0,degree + 1): coefficient = input('Enter the coefficient for x^ %i ? ' %i) coef.append(coefficient) s= Poly (c = coef) m= Poly (c = coef) s.integrate() m.Derivative() print "the integral of your polynomial is:" print "c +",s print "the derivative of your polynomial is:",m Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From kromag@nsacom.net Fri May 4 04:53:32 2001 From: kromag@nsacom.net (kromag@nsacom.net) Date: Thu, 3 May 2001 20:53:32 -0700 (PDT) Subject: [Tutor] starting a tkinter window maximized Message-ID: <200105040353.f443rWo07415@pop.nsacom.net> Harry Kattz said: > wm_state('zoomed') should maximize on Windows. For example: > > >>> import os > >>> from Tkinter import * > >>> class MaxWin(Tk): > ... def __init__(self): > ... Tk.__init__(self) > ... Label(self, text = "Test Zoom").pack() > ... if os.name == 'nt': > ... self.wm_state('zoomed') > ... > >>> test = MaxWin() > >>> test.mainloop() > > This produced a full size window with a label. > Hrm.. Does this work in win9x as opposed to NT? This does not appear to work on my 95 and 98 boxes. d From tbaruch@mindless.com Fri May 4 02:45:34 2001 From: tbaruch@mindless.com (Timothy M. Brauch) Date: Thu, 03 May 2001 21:45:34 -0400 Subject: [Tutor] Linux Programs Message-ID: <3AF209BE.6BE4C132@mindless.com> Okay, I'm slowly making a move from Windows to (Red Hat 7.0) Linux, but there are somethings in Linux that I just can't figure out how to do. One of these things is using Python. I can open the Python interpreter (by typing 'python' in the terminal window). I can even open Idle when I am running xWindows (I just type 'idle' in the terminal). And, I can write and run programs in Idle. But, the problem comes after that. I can't get my programs to run outside of Idle. I know I have to add a line at the beginning of each python file, but I don't know what that line is. When I wrote Python files for a class on the (Mandrake) Linux machines, the line was: #!/usr/bin/python This line doesn't work on my computer. All I get is the file openned in a text editor. I have Python installed in /usr/lib/python1.5/ because that is where it was installed when I installed Linux. /usr/bin/python and /usr/bin/python1.5 both exist, but putting '#!/usr/bin/python' or '#!/usr/bin/python1.5' still opens the files in a text editor, even if I saved the file as 'test.py' Can anyone help me? I need to be able to write Python programs so I can start my assignment of creating the Processor Simulator. - Tim From kauphlyn@speakeasy.org Fri May 4 03:22:39 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Thu, 3 May 2001 19:22:39 -0700 (PDT) Subject: [Tutor] Linux Programs In-Reply-To: <3AF209BE.6BE4C132@mindless.com> Message-ID: I am guessing you have permissions set up correctly, but if not type in man chmod at the command prompt to figure out how to get the permissions set correctly. secondly and most likely the directory youre running test.py out of probably isnt in your path. you can check this by typing echo $PATH at the command prompt to add the directory to your path you can type export PATH=$PATH: /home/myuserdirecory/mypython or whatever your directory is. you should also be able to run your python program by typing ./test.py at the command prompt even if you dont change your path. hope this helps Daniel On Thu, 3 May 2001, Timothy M. Brauch wrote: > Okay, I'm slowly making a move from Windows to (Red Hat 7.0) Linux, but > there are somethings in Linux that I just can't figure out how to do. > One of these things is using Python. > > I can open the Python interpreter (by typing 'python' in the terminal > window). I can even open Idle when I am running xWindows (I just type > 'idle' in the terminal). And, I can write and run programs in Idle. > > But, the problem comes after that. I can't get my programs to run > outside of Idle. I know I have to add a line at the beginning of each > python file, but I don't know what that line is. When I wrote Python > files for a class on the (Mandrake) Linux machines, the line was: > > #!/usr/bin/python > > This line doesn't work on my computer. All I get is the file openned in > a text editor. I have Python installed in /usr/lib/python1.5/ because > that is where it was installed when I installed Linux. /usr/bin/python > and /usr/bin/python1.5 both exist, but putting '#!/usr/bin/python' or > '#!/usr/bin/python1.5' still opens the files in a text editor, even if I > saved the file as 'test.py' > > Can anyone help me? I need to be able to write Python programs so I can > start my assignment of creating the Processor Simulator. > > - Tim > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From arcege@speakeasy.net Fri May 4 03:30:17 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Thu, 3 May 2001 22:30:17 -0400 (EDT) Subject: [Tutor] range In-Reply-To: from "Julieta Rangel" at May 03, 2001 06:27:25 PM Message-ID: <200105040230.f442UHk01024@dsl092-074-184.bos1.dsl.speakeasy.net> Julieta Rangel wrote > > I have the following program but when I run it it only runs half-ways. It > displays a message of out of range. Can you tell me what I'm doing wrong? > > class Poly: > def __init__ ( self, v='x' , c = [0]): > """__init__(): > Initializes a polynomial > Default variable is x > Default polynomial is zero""" > self.var = v > self.coef = c > self.deg = len(c)-1 > self.length = len(c) > def __str__ (self): > """__str__(): > Converts a polynomial into a string""" > x = `self.coef[0]` > for i in range (1,self.deg+1): > x = x + "+" +`self.coef[i]` + self.var + "^" + `i` > return x All sequences in Python start at 0 and go up to len(seq)-1 for indices. Your range starts at 1 and goes to len(seq). The last index doesn't exist in the sequence. Try changing the range to (1, self.deg). > def integrate(self): > """Input: an instance of a polynommial > Output: a polynomial that is the integral of the input > polynomial > Side Effects: None""" > > coef=[0] > self.deg= self.deg +1 > for i in range(0,self.deg): > coef.append(self.coef[i]/float(i+1)) > self.coef= coef > > def Derivative(self): > """Input: an instance of a polynomial > Output: a polynomial that is the derivative of the input polynomial > side Effects: None""" > coef=[1] > self.deg= self.deg +1 > if self.deg==0: > coef=[0] > else: > for i in range(0,self.deg-1): > coef.append((i+1)*self.coef[i+1]) > self.coef= coef I think this is the problem. You increment self.deg, but don't add as many values as necessary. Try decrementing self.deg. >From pdb: (Pdb) cont the integral of your polynomial is: c + 1 2 0+1.0x^1+1.0x^2 the derivative of your polynomial is: 1 2 IndexError: 'list index out of range' > (1)?()->2 (Pdb) where > (1)?()->2 /tmp/try.py(93)?()->2 -> print "the derivative of your polynomial is:",m /tmp/try.py(53)__str__() -> x = x + "+" +`self.coef[i]` + self.var + "^" + `i` (Pdb) down > /tmp/try.py(93)?()->2 -> print "the derivative of your polynomial is:",m (Pdb) down > /tmp/try.py(53)__str__() -> x = x + "+" +`self.coef[i]` + self.var + "^" + `i` (Pdb) print self.coef [1, 2] (Pdb) print i 2 (Pdb) print self.deg 2 (Pdb) > degree = input('Enter the degree of your polynomial') > coef=[] > for i in range (0,degree + 1): > coefficient = input('Enter the coefficient for x^ %i ? ' %i) > coef.append(coefficient) > > s= Poly (c = coef) > m= Poly (c = coef) > s.integrate() > m.Derivative() > print "the integral of your polynomial is:" > print "c +",s > print "the derivative of your polynomial is:",m Also, think about changing things such that the integrate and derivative methods return _new_ Poly objects and to _not_ modify 'self'. -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From wall@adinet.com.uy Fri May 4 03:41:50 2001 From: wall@adinet.com.uy (Walter Moreira) Date: Thu, 3 May 2001 23:41:50 -0300 Subject: [Tutor] Few simple question. In-Reply-To: <001501c0d37e$424a9ce0$6a01a8c0@com.my>; from arazak@kansai.com.my on Thu, May 03, 2001 at 11:07:54AM +0800 References: <001501c0d37e$424a9ce0$6a01a8c0@com.my> Message-ID: <20010503234150.B23778@casa.parque> On Thu, May 03, 2001 at 11:07:54AM +0800, Mr. Razak wrote: > > 1). I want to know how to change colour, i mean how to used colour in python language. > > 2). How to used coordinate system, or may be there is a module i can used to help me. For example on the computer screen at a location row=5, column 35, I want to print 'Hello world'. How to do that. > > 3). How to create box and how place it on the computer screen on the desirerable location. You can take a look at the Demo/curses directory of the Python distribution. There are examples for using color and boxes and printing in coordinates. You can use the curses module just with >>> import curses But, if you are looking for graphical windows, then look in Doc/tkinter. I think curses is easier. Hope it helps: -- Walter -- -------------- Walter Moreira <> Centro de Matematica <> Universidad de la Republica email: walterm@cmat.edu.uy <> HomePage: http://www.cmat.edu.uy/~walterm +----------------------------------------------------- /OD\_ | Contrary to popular belief, Unix is user friendly. O o . |_o_o_) | It just happens to be very selective about who its | friends are. -- Kyle Hearn --+-- From rick@niof.net Fri May 4 04:05:17 2001 From: rick@niof.net (Rick Pasotto) Date: Thu, 3 May 2001 23:05:17 -0400 Subject: [Tutor] Linux Programs In-Reply-To: <3AF209BE.6BE4C132@mindless.com>; from tbaruch@mindless.com on Thu, May 03, 2001 at 09:45:34PM -0400 References: <3AF209BE.6BE4C132@mindless.com> Message-ID: <20010503230517.E13123@tc.niof.net> On Thu, May 03, 2001 at 09:45:34PM -0400, Timothy M. Brauch wrote: > Okay, I'm slowly making a move from Windows to (Red Hat 7.0) Linux, but > there are somethings in Linux that I just can't figure out how to do. > One of these things is using Python. > > I can open the Python interpreter (by typing 'python' in the terminal > window). I can even open Idle when I am running xWindows (I just type > 'idle' in the terminal). And, I can write and run programs in Idle. > > But, the problem comes after that. I can't get my programs to run > outside of Idle. I know I have to add a line at the beginning of each > python file, but I don't know what that line is. When I wrote Python > files for a class on the (Mandrake) Linux machines, the line was: > > #!/usr/bin/python I think the prefered way is: #!/usr/bin/env python This should find the appropriate python no matter where it's located. > This line doesn't work on my computer. All I get is the file openned in > a text editor. Huh? This doesn't make sense to me. In unix you don't get an editor unless you *ask* for an editor. How are you trying to run the file? What is your command line? Or are you in X and clicking on an icon? Even without the '#!' line and regardless of the permissions (well, you do need 'read' permission) you can run your program by entering: python test.py -- "The financial policy of the welfare state requires that there be no way for the owners of wealth to protect themselves. This is the shabby secret of the welfare statists' tirades against gold. Deficit spending is simply a scheme for the 'hidden' confiscation of wealth. Gold stands in the way of this insidious process. It stands as a protector of property rights." -- Alan Greenspan Rick Pasotto email: rickp@telocity.com From tbaruch@mindless.com Fri May 4 04:48:33 2001 From: tbaruch@mindless.com (Timothy M. Brauch) Date: Thu, 03 May 2001 23:48:33 -0400 Subject: [Tutor] Linux Programs References: <3AF209BE.6BE4C132@mindless.com> <20010503230517.E13123@tc.niof.net> Message-ID: <3AF22691.50E57499@mindless.com> Rick Pasotto wrote: > > I think the prefered way is: > > #!/usr/bin/env python > > This should find the appropriate python no matter where it's located. > > > This line doesn't work on my computer. All I get is the file openned in > > a text editor. > > Huh? This doesn't make sense to me. In unix you don't get an editor > unless you *ask* for an editor. > > How are you trying to run the file? What is your command line? Or are > you in X and clicking on an icon? > > Even without the '#!' line and regardless of the permissions (well, you > do need 'read' permission) you can run your program by entering: > > python test.py Yeah, I realized that right after I sent this, I probably wouldn't be able to just click on an icon in X, like I was used to in Windows. But, I am also having problems using command line. Still, I can run the program using 'python test.py' if I am in the folder 'test.py' is stored. I am still wondering if it is possible to just type 'test.py' (as long as I am in the folder, or preferrably, anywhere). I tried using 'export PATH=$PATH: /home/tbrauch/python_files' but I get the following error message bash: export: `/home/tbrauch/python_files': not a valid identifier I'm not trying to turn this into a Linux tutorial, I just hope to get Python working on my new computer... - Tim From dyoo@hkn.eecs.berkeley.edu Fri May 4 06:11:34 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 3 May 2001 22:11:34 -0700 (PDT) Subject: [Tutor] Cackling with Maniac Laughter (was: starting a tkinter window maximized) In-Reply-To: <200105032308.f43N8Oo06988@pop.nsacom.net> Message-ID: > Good heavens yes it is rude. Unfortunately I am stuck with Win9x for this > particular experiment! :-) > > What I am trying to do is pop up a window as a screen saverish app that > displays information rather than a cute bouncing whatsis. I 'compiled' the > program with py2exe (a wonderful program!) then switched it's extention > to .scr. Walla! A badly-behaved screensaver! If you're interested in doing animation/game stuff in Python, you might be interested in pygame: http://pygame.seul.org/ It should work on Windows as well, though I haven't tried yet. From dyoo@hkn.eecs.berkeley.edu Fri May 4 06:15:15 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 3 May 2001 22:15:15 -0700 (PDT) Subject: [Tutor] Linux Programs In-Reply-To: <3AF209BE.6BE4C132@mindless.com> Message-ID: On Thu, 3 May 2001, Timothy M. Brauch wrote: > > But, the problem comes after that. I can't get my programs to run > outside of Idle. I know I have to add a line at the beginning of each > python file, but I don't know what that line is. When I wrote Python > files for a class on the (Mandrake) Linux machines, the line was: > > #!/usr/bin/python > > This line doesn't work on my computer. All I get is the file openned in > a text editor. I have Python installed in /usr/lib/python1.5/ because > that is where it was installed when I installed Linux. /usr/bin/python > and /usr/bin/python1.5 both exist, but putting '#!/usr/bin/python' or > '#!/usr/bin/python1.5' still opens the files in a text editor, even if I > saved the file as 'test.py' > > Can anyone help me? I need to be able to write Python programs so I can > start my assignment of creating the Processor Simulator. One other thing you might need to do is make the file "executable" --- that is, you need to flag it so that Linux knows that it's supposed to be run as a program. At the moment, Mandrake's file manager probably still thinks that it should be treated as a text document. If you know about the command line shell, try this: $ chmod +x test.py which tells the system to flag the "eXecutable" bit on a file. This flagging, combined with the magic line "#!/usr/bin/python", should do the trick. From dyoo@hkn.eecs.berkeley.edu Fri May 4 06:33:31 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 3 May 2001 22:33:31 -0700 (PDT) Subject: [Tutor] Guido and ESR post to Useless Python In-Reply-To: <000a01c0d3f5$ef481220$de00a8c0@planhouse5> Message-ID: On Thu, 3 May 2001, Rob Andrews wrote: > I'll get the code posted tonight, but wanted to go ahead and spread a little > glee. Guido van Rossum and Eric S. Raymond (Open Source programming deity) > have both submitted code to be posted on Useless Python today. Congratulations! This is very cool. From dyoo@hkn.eecs.berkeley.edu Fri May 4 06:41:33 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 3 May 2001 22:41:33 -0700 (PDT) Subject: [Tutor] inserting items into a list In-Reply-To: Message-ID: On Thu, 3 May 2001, Julieta Rangel wrote: > [3,0,6], then [1,0,2] and finally [2,0,4]. I need to find a way to insert 3 > zeroes at the end of list [2,0,4]; 1 zero at the beginning and two at the > end of [3,0,6]; 2 zeroes a the beginning and one at the end of [1,0,2], and > finally 3 zeroes at the beginning of [2,0,4]. This way the new lists would > look like: > > [2,0,4,0,0,0] > [0,3,0,6,0,0] > [0,0,1,0,2,0] > [0,0,0,2,0,4] > > and it would be just a matter of adding those lists to figure out the > result: 2 + 3x + 5x^2 + 8x^3 + 2x^4 + 4x^5. As you can see from the > subject, my problem is inserting those zeroes at the specific locations. > Can you help me? How about something like this? ### def makeZeroPaddedList(mylist, position, length): """This function should take mylist, and splice it into a list of zeros at a specific location.""" newlist = [0] * length newlist[position:position + len(mylist)] = mylist return newlist ### Let's test it out on the interpreter: ### >>> makeZeroPaddedList([1, 2, 3], 0, 10) [1, 2, 3, 0, 0, 0, 0, 0, 0, 0] >>> makeZeroPaddedList([1, 2, 3], 1, 10) [0, 1, 2, 3, 0, 0, 0, 0, 0, 0] >>> makeZeroPaddedList([1, 2, 3], 2, 10) [0, 0, 1, 2, 3, 0, 0, 0, 0, 0] >>> makeZeroPaddedList([1, 2, 3], 3, 10) [0, 0, 0, 1, 2, 3, 0, 0, 0, 0] >>> makeZeroPaddedList([1, 2, 3], 4, 10) [0, 0, 0, 0, 1, 2, 3, 0, 0, 0] ### The idea is to make up a list that's filled only with zeros, and then plop our original list into it. We can control both the position of the plopping, and the length of the resulting list. Hope this helps! From bsass@freenet.edmonton.ab.ca Fri May 4 06:42:33 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Thu, 3 May 2001 23:42:33 -0600 (MDT) Subject: [Tutor] Linux Programs In-Reply-To: <3AF22691.50E57499@mindless.com> Message-ID: On Thu, 3 May 2001, Timothy M. Brauch wrote: > Rick Pasotto wrote: > > > > I think the prefered way is: > > > > #!/usr/bin/env python > > > > This should find the appropriate python no matter where it's located. Ya. /usr/bin/env should exist on every(?) unix-like system, it will find the interpreter, which could be in /usr/bin, /usr/local/bin, etc. I recommend using: "#!/usr/bin/env pythonX.Y", if the script will only work with python version X.Y - you may only have one version of python installed, I have three. > > > This line doesn't work on my computer. All I get is the file openned in > > > a text editor. > > > > Huh? This doesn't make sense to me. In unix you don't get an editor > > unless you *ask* for an editor. > > > > How are you trying to run the file? What is your command line? Or are > > you in X and clicking on an icon? > > > > Even without the '#!' line and regardless of the permissions (well, you > > do need 'read' permission) you can run your program by entering: > > > > python test.py > > Yeah, I realized that right after I sent this, I probably wouldn't be > able to just click on an icon in X, like I was used to in Windows. But, That will depend on which window manager/desktop you are using. I'm using KDE and can get an icon to do pretty much anything when clicked on (expect to fiddle a bit, downside of not having a central controling authority that dictates what is "right"). > I am also having problems using command line. Still, I can run the > program using 'python test.py' if I am in the folder 'test.py' is > stored. I am still wondering if it is possible to just type 'test.py' A period (".") is defined as the current working directory. So you can do "./test.py" to run something in the dir you are in (resist the temptation to add "." to your PATH). Otherwise you use the full path, or put (or symlink) the programs in a dir on your path (/usr/local/bin is a good choice, and adding a bin dir to your home dir is fairly common). > (as long as I am in the folder, or preferrably, anywhere). I tried > using 'export PATH=$PATH: /home/tbrauch/python_files' but I get the > following error message > > bash: export: `/home/tbrauch/python_files': not a valid identifier try: "export PATH=$PATH:/home/tbrauch/bin" instead (or python_files, whatever turns your crank). i.e., drop the space and the single quotes, bash sees the /home/... bit as an environment var to be exported. > I'm not trying to turn this into a Linux tutorial, I just hope to get > Python working on my new computer... :) - Bruce From sheila@thinkspot.net Fri May 4 06:48:41 2001 From: sheila@thinkspot.net (Sheila King) Date: Thu, 03 May 2001 22:48:41 -0700 Subject: [Tutor] inserting items into a list In-Reply-To: <6245C1B04BC@kserver.org> References: <6245C1B04BC@kserver.org> Message-ID: <9839C343BF@kserver.org> On Thu, 03 May 2001 16:27:00 -0700, Sheila King wrote about Re: [Tutor] inserting items into a list: :SK> I would note, that since you are multiplying a 3rd degree polynomial by a :SK> 2nd degree one, that your result should be fifth degree. You could find :SK> this out by doing len(p1)-1 added to len(p2)-1 then create a new :SK> list to store the results of your multiplication. Give it length of :SK> 5 and initialize all spots to zero. Let's call this new list for the :SK> result, p3. Er... there's an error in what I suggest above. (Maybe you caught it already?) Multiplying a 3rd degree poly by a 2nd degree poly does indeed give a 5th degree poly. HOWEVER, for the resulting 5th deg poly, you need to create a list of length 6, NOT length 5. Doh! -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From jsc_lists@rock-tnsc.com Fri May 4 23:12:55 2001 From: jsc_lists@rock-tnsc.com (Jethro Cramp) Date: Fri, 4 May 2001 14:12:55 -0800 Subject: [Tutor] Unpickling a Pickled Object Message-ID: <01050414125502.00931@jsclaptop> When a pickled object is unpickled does __init__ get called. I can think of half a dozen reasons why it shouldn't, but just thought I'd ask. TIA, Jethro From learnpython@hotmail.com Fri May 4 07:28:06 2001 From: learnpython@hotmail.com (Learn Python) Date: Fri, 04 May 2001 06:28:06 -0000 Subject: [Tutor] Python book suggestion please Message-ID: hi all, i'm new to python and i do java @ work. I'm looking to buy a good / probably the best reference book available right now in the market. I checked out a few titles and arrived at the follwing titles: 1. Programming Python 2nd edition (orielly) 2. Python programmer's refernce (Insider Press)..by Beazely ( this is not uptodate i guess since it does'nt cover 2.0) C'd someone please suggest a good buy. Any thoughts? thanks, karthik. _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From sburr@mac.com Fri May 4 07:58:03 2001 From: sburr@mac.com (Steven Burr) Date: Thu, 3 May 2001 23:58:03 -0700 Subject: [Tutor] Cackling with Maniac Laughter (was: starting a tkinter window maximized) In-Reply-To: <200105032308.f43N8Oo06988@pop.nsacom.net> Message-ID: <20010504065723.LWVD18489.femail17.sdc1.sfba.home.com@localhost> On Thursday, May 3, 2001, at 04:08 PM, wrote: > I cackled with Maniac Laughter as as my little script popped up after 60 > seconds! :-) Show of hands. Who else would like to see "Mr. Yoo" substitute *cackling with maniac laughter* for *grin*? Sorry, but I wrote what seemed like 100 e-mails at work today, and I can't seem to stop. I'll go bother someone else now. From toodles@yifan.net Fri May 4 09:10:26 2001 From: toodles@yifan.net (Andrew Wilkins) Date: Fri, 4 May 2001 16:10:26 +0800 Subject: [Tutor] Unpickling a Pickled Object In-Reply-To: <01050414125502.00931@jsclaptop> Message-ID: Hi Jethro, I'll just post what it says in the documentation: """ When a pickled class instance is unpickled, its __init__() method is normally not invoked. Note: This is a deviation from previous versions of this module; the change was introduced in Python 1.5b2. The reason for the change is that in many cases it is desirable to have a constructor that requires arguments; it is a (minor) nuisance to have to provide a __getinitargs__() method. If it is desirable that the __init__() method be called on unpickling, a class can define a method __getinitargs__(), which should return a tuple containing the arguments to be passed to the class constructor (__init__()). This method is called at pickle time; the tuple it returns is incorporated in the pickle for the instance. """ I hope that helps =) Andrew > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Jethro Cramp > Sent: Saturday, 5 May 2001 6:13 AM > To: Tutor@python.org > Subject: [Tutor] Unpickling a Pickled Object > > > When a pickled object is unpickled does __init__ get called. I can > think of half a dozen reasons why it shouldn't, but just thought I'd ask. > > TIA, > > Jethro > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From learnpython@hotmail.com Fri May 4 09:19:18 2001 From: learnpython@hotmail.com (Learn Python) Date: Fri, 04 May 2001 08:19:18 -0000 Subject: [Tutor] Unpickling a Pickled Object Message-ID: hi Jethro, c'd you please tell why you think the __init__ s'd'nt be called? If i'm doing some initialisation in __init__ whch in turn will be used by other methods then the unpickling w'd'nt be of much use right? my code might fail bcos certain things did'nt get initialized. Do we have a private void readObject() java equivalent in python? which w'd automatically get called when we "deserialize" the object / in this case "unpickle". Then we can probably initialize some stuff there? karthik _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From rwilkins@bigpond.net.au Fri May 4 10:04:39 2001 From: rwilkins@bigpond.net.au (Richard Wilkins) Date: Fri, 4 May 2001 17:04:39 +0800 Subject: [Tutor] Sort of non-related...but in a way, related too...*grins* Message-ID: Hi folks, I'm releasing my MUD server package to Useless, the main framework is set...it runs fairly smoothly (as far as I'm concerned!) What I need to know is, what is the most commonly used archiving file-type...tarballs? I'm coming from a completely Windows background, so I just use zip. If someone would kindly tell me which one to use, if it actually matters, then I'll submit it... Thanks, Andrew From dyoo@hkn.eecs.berkeley.edu Fri May 4 10:03:56 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 4 May 2001 02:03:56 -0700 (PDT) Subject: [Tutor] Python book suggestion please In-Reply-To: Message-ID: On Fri, 4 May 2001, Learn Python wrote: > i'm new to python and i do java @ work. Nice to meet you! > I'm looking to buy a good / probably the best reference > book available right now in the market. I checked out > a few titles and arrived at the follwing titles: > > 1. Programming Python 2nd edition (orielly) > 2. Python programmer's refernce (Insider Press)..by Beazely ( this is not > uptodate i guess since it does'nt cover 2.0) The following is just my opinions, so please take it with a grain of salt: 1. Programming Python is big and heavy. Usually, this is a good thing because it allows the author to be comprehensive. It's also an advantage if you want to improve your hand grip. The book seems a bit too spread out, so it might not be useful as a reference. It's good reading, but if you're in a hurry, this might not be your first choice. 2. "Learning Python" by Mark Lutz is a good book if you're already familiar with a computer language. It's not too heavy, unlike Programming Python, and it hits the core features of Python very quickly. I highly recommend it. 3. David Beazley's "Python Essential Reference" is amazingly well organized. I find myself looking at it if I can't get at online documentation. However, it is also targeted on Python 1.52, so I hope that Beazley updates it soon. It's a very good reference, and easy to find things, very informative, and condensed. 4. Wesley Chun has just written "Core Python Programming", and since he's one of the tutor@python.org list operators, it would be simply criminal not to mention his book. (Ahem.) I've heard good things about it, but haven't had the chance to buy it yet. However, you might not even need to buy a book: check out the Python tutorial: http://python.org/doc/current/tut/tut.html Its intended audience are those who already know how to program in a language like C, C++, Perl, or Java, so it should be very useful for you. You may be able to learn (or at least, see) the core of Python in an hour by going through the tutorial. Also, the library reference is downloadable from here: http://python.org/doc/current/download.html so you can always keep a local copy on your computer. If you have any questions, feel free to ask us on tutor. Good luck to you. From rob@jam.rr.com Fri May 4 11:53:08 2001 From: rob@jam.rr.com (rob@jam.rr.com) Date: Fri, 04 May 2001 05:53:08 -0500 Subject: [Tutor] Python book suggestion please References: Message-ID: <3AF28A14.2A492739@jam.rr.com> I know you asked for a book recommendation, but there is a good bit of online reference material available, such as the good list found at: http://www.lowerstandard.com/python/howtolinks.html Rob Learn Python wrote: > > hi all, > > i'm new to python and i do java @ work. > I'm looking to buy a good / probably the best reference > book available right now in the market. I checked out > a few titles and arrived at the follwing titles: > > 1. Programming Python 2nd edition (orielly) > 2. Python programmer's refernce (Insider Press)..by Beazely ( this is not > uptodate i guess since it does'nt cover 2.0) > > C'd someone please suggest a good buy. Any thoughts? > > thanks, > karthik. > _________________________________________________________________________ > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From LloydJ@missouri.edu Fri May 4 12:01:39 2001 From: LloydJ@missouri.edu (Lloyd, Jamie) Date: Fri, 4 May 2001 06:01:39 -0500 Subject: [Tutor] how to input a name Message-ID: <44D2ED0AC0121146BF01366481060EBE607146@umc-mail02.missouri.edu> I would like to make a program that would ask for a person's name, then say " Hello (persons name)!" this is what I thought would work... #!/usr/local/bin/env python name = input("What is your name?") print name But as you can guess this does not work, any suggestions? Jamie Lloyd Data Center Tech IATS/UCSOperations University of Missouri From rob@jam.rr.com Fri May 4 12:05:22 2001 From: rob@jam.rr.com (rob@jam.rr.com) Date: Fri, 04 May 2001 06:05:22 -0500 Subject: [Tutor] Sort of non-related...but in a way, related too...*grins* References: Message-ID: <3AF28CF2.44A97A7A@jam.rr.com> So far, a few people have submitted tarballs and zip files, and either is fine. If I receive a tarball, I'm likely to post a copy in .zip format for those windows users who are unfamiliar with tarballs. If you just send a zip archive, I'll likely leave it as it is unless someone complains. Thanks for remembering Useless, Rob Richard Wilkins wrote: > > Hi folks, > > I'm releasing my MUD server package to Useless, the main framework is > set...it runs fairly smoothly > (as far as I'm concerned!) > > What I need to know is, what is the most commonly used archiving > file-type...tarballs? I'm coming from a completely Windows background, so I > just use zip. If someone would kindly tell me which one to use, if it > actually matters, then I'll submit it... > > Thanks, > > Andrew > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From rob@jam.rr.com Fri May 4 12:06:42 2001 From: rob@jam.rr.com (rob@jam.rr.com) Date: Fri, 04 May 2001 06:06:42 -0500 Subject: [Tutor] Python book suggestion please References: Message-ID: <3AF28D42.2B43B70F@jam.rr.com> I know you asked for a book recommendation, but there is a good bit of online reference material available, such as the good list found at: http://www.lowerstandard.com/python/howtolinks.html Rob Learn Python wrote: > > hi all, > > i'm new to python and i do java @ work. > I'm looking to buy a good / probably the best reference > book available right now in the market. I checked out > a few titles and arrived at the follwing titles: > > 1. Programming Python 2nd edition (orielly) > 2. Python programmer's refernce (Insider Press)..by Beazely ( this is not > uptodate i guess since it does'nt cover 2.0) > > C'd someone please suggest a good buy. Any thoughts? > > thanks, > karthik. -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From learnpython@hotmail.com Fri May 4 12:14:11 2001 From: learnpython@hotmail.com (Learn Python) Date: Fri, 04 May 2001 11:14:11 -0000 Subject: [Tutor] how to input a name Message-ID: name=raw_input("name??") print name will work. I guess the problem is that input() expects a python data type so supplying 'yourname' w'd've worked since it's a string wheareas just yourname w/o "'" is'nt one. raw_input aceepts anything you supply. karthik. >From: "Lloyd, Jamie" >To: "Tutor@Python. Org (E-mail)" >Subject: [Tutor] how to input a name >Date: Fri, 4 May 2001 06:01:39 -0500 > >I would like to make a program that would ask for a person's name, then say >" Hello (persons name)!" > >this is what I thought would work... > >#!/usr/local/bin/env python > >name = input("What is your name?") >print name > > >But as you can guess this does not work, any suggestions? > > >Jamie Lloyd >Data Center Tech >IATS/UCSOperations >University of Missouri > > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From toodles@yifan.net Fri May 4 12:19:33 2001 From: toodles@yifan.net (Andrew Wilkins) Date: Fri, 4 May 2001 19:19:33 +0800 Subject: [Tutor] how to input a name In-Reply-To: <44D2ED0AC0121146BF01366481060EBE607147@umc-mail02.missouri.edu> Message-ID: > OMG.. thanks so much.. ! If it were not for people like you, my > life would > not be much fun. > Again, thanks for the info! No problems! Sorry for sending that reply directly to you, it was meant to go to the list... Andrew From wilson@visi.com Fri May 4 13:09:43 2001 From: wilson@visi.com (Timothy Wilson) Date: Fri, 4 May 2001 07:09:43 -0500 (CDT) Subject: [Tutor] Python book suggestion please In-Reply-To: Message-ID: On Fri, 4 May 2001, Daniel Yoo wrote: > 4. Wesley Chun has just written "Core Python Programming", and since > he's one of the tutor@python.org list operators, it would be simply > criminal not to mention his book. (Ahem.) I've heard good things about > it, but haven't had the chance to buy it yet. Well I've had the chance to buy and read most of it. It's excellent. Wesley's book is probably the best I've read so far. I like the mix of basic and more advanced topics at the end. The exercises in the back of the chapter are the best I've seen. (I plan to steal liberally from them next year when I teach my Python class :-) -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.org W. St. Paul, MN | | http://slashdot.org wilson@visi.com | | http://linux.com From lonetwin@yahoo.com Fri May 4 13:31:28 2001 From: lonetwin@yahoo.com (steve) Date: Fri, 4 May 2001 18:01:28 +0530 Subject: [Tutor] Regular-ex to parse man files Message-ID: <01050418012800.02176@mercury.in.cqsl.com> Hi all, Here's a lil' prob. I'm facing, for a script I'm writing, I need to pars= e=20 man files (the unix manual files) and get the DESCRIPTION part from 'em .= =2E..I=20 tried to do this by reading the man file directly and doing a regular-ex=20 search for .SH DESCRIPTION and reading from then on......now I'm just=20 learning python and I'm not too comfy with regex as yet, any suggestions = on=20 how I could get this done ?? Plz. don't blame me for not trying, I've written here after going thru' = the=20 regex howto, reading code snippets from various places and wasting a day=20 experimenting.....I've just come close to getting it done....but as u kno= w,=20 there's a big diffrence between getting close to doing it, and doing it != ! :) Thanx in advance, Peace Steve --=20 |||||||||||||||||||||| |||||||||#####|||||||| ||||||||#######||||||| ||||||||# O O #||||||| ||||||||#\ ~ /#||||||| ||||||##||\_/||##||||| |||||#||||||||||##|||| ||||#||||||||||||##||| ||||#|||||||||||||##||=09 |||/\##|||||||||##/\||=09 |/ \#########/ \=09 |\ \#######/ /=09 ||\____/#######\____/|=09 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=09 "Unfortunately, those people who have nothing better to do than post on t= he Internet all day long are rarely the ones who have the most insights." =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D From Mark A. Tobin" Hi again, first I want to thank everybody who helped explain the whole self thing as it has to do with classes, I think I'm slowly getting the idea. second I'm having a problem with urlretrieve() and I'm not even sure where the problem resides. Maybe some of you python/windows people out there might be able to help. I'm running two systems both Win95, one runs 1.5.2, and one 2.0. Both systems are similarly configured, at least as far as I know to look. When I do this: >>>from urllib import urlretrieve >>>urlretrieve("http://www.ihrg.com/nssnet/default.htm", "test.htm") ('test.htm', ) it looks like it worked right? well on the system using 1.5.2 it does work, I get that webpage, intact, saved in the appropriate file. However, on the other system (running python 2.0) I get a webpage giving me a standard Proxy authorization required message instead of the page I'm looking for: Proxy authorization required Username authentication is required for using this proxy. Either your browser does not perform proxy authorization, or your authorization has failed. I wondered whether it was that specific server so I tried with python.org and got the same message. Both systems use the same dialup ISP connection, and as far as I know there certainly is no Proxy associated with either system. I have never had to do anything proxy associated during any setup process, and when I grab that file with IE5 it works like a charm. Any suggestions? I wasn't really sure what info might be relevant, so I may not have provided everything a diagnostician might need. I don't even really know where to look.... Looking for help (again... sigh), Mark From randrews@planhouse.com Fri May 4 16:45:50 2001 From: randrews@planhouse.com (Rob Andrews) Date: Fri, 4 May 2001 10:45:50 -0500 Subject: [Tutor] urlretrieve In-Reply-To: <000901c0d4af$648cfaa0$e9b8c28e@anonymous> Message-ID: <001701c0d4b1$4c11aaa0$de00a8c0@planhouse5> Are you using Netscape when you encounter the problem? If so, look under Edit>Preferences. I think that under this you will find Advanced>Proxies and may find that it expects a proxy now for some reason. There are a number of somewhat rare reasons this can happen. If it is the case, you can easily enough set it straight from there. Rob -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of Mark A. Tobin Sent: Friday, May 04, 2001 10:32 AM To: tutor@python.org Subject: [Tutor] urlretrieve Hi again, first I want to thank everybody who helped explain the whole self thing as it has to do with classes, I think I'm slowly getting the idea. second I'm having a problem with urlretrieve() and I'm not even sure where the problem resides. Maybe some of you python/windows people out there might be able to help. I'm running two systems both Win95, one runs 1.5.2, and one 2.0. Both systems are similarly configured, at least as far as I know to look. When I do this: >>>from urllib import urlretrieve >>>urlretrieve("http://www.ihrg.com/nssnet/default.htm", "test.htm") ('test.htm', ) it looks like it worked right? well on the system using 1.5.2 it does work, I get that webpage, intact, saved in the appropriate file. However, on the other system (running python 2.0) I get a webpage giving me a standard Proxy authorization required message instead of the page I'm looking for: Proxy authorization required Username authentication is required for using this proxy. Either your browser does not perform proxy authorization, or your authorization has failed. I wondered whether it was that specific server so I tried with python.org and got the same message. Both systems use the same dialup ISP connection, and as far as I know there certainly is no Proxy associated with either system. I have never had to do anything proxy associated during any setup process, and when I grab that file with IE5 it works like a charm. Any suggestions? I wasn't really sure what info might be relevant, so I may not have provided everything a diagnostician might need. I don't even really know where to look.... Looking for help (again... sigh), Mark _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From Mark A. Tobin" Message-ID: <004101c0d4b6$0314b900$e9b8c28e@anonymous> Rob, thanks for your prompt reply. I don't have Netscape installed on that system, however I took the advice anyway and checked the Internet Options that IE5 employs. Other than thinking it was connected using a LAN it was setup fine. All the proxy options were cleared. Just to be safe I changed the LAN to dialup and retested with the same result. Do the options in there affect how python connects to servers? Wouldn't they affect IE5's ability to grab the page as well? Any other ideas? I'm completely at a loss... Mark ----- Original Message ----- From: "Rob Andrews" To: "'Mark A. Tobin'" ; Sent: Friday, May 04, 2001 11:45 AM Subject: RE: [Tutor] urlretrieve > Are you using Netscape when you encounter the problem? If so, look under > Edit>Preferences. I think that under this you will find Advanced>Proxies and > may find that it expects a proxy now for some reason. There are a number of > somewhat rare reasons this can happen. If it is the case, you can easily > enough set it straight from there. > > Rob > > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Mark A. Tobin > Sent: Friday, May 04, 2001 10:32 AM > To: tutor@python.org > Subject: [Tutor] urlretrieve > > > Hi again, > first I want to thank everybody who helped explain the whole self thing as > it has to do with classes, I think I'm slowly getting the idea. > second I'm having a problem with urlretrieve() and I'm not even sure where > the problem resides. Maybe some of you python/windows people out there > might be able to help. > I'm running two systems both Win95, one runs 1.5.2, and one 2.0. Both > systems are similarly configured, at least as far as I know to look. When I > do this: > >>>from urllib import urlretrieve > >>>urlretrieve("http://www.ihrg.com/nssnet/default.htm", "test.htm") > ('test.htm', ) > it looks like it worked right? > well on the system using 1.5.2 it does work, I get that webpage, intact, > saved in the appropriate file. However, on the other system (running python > 2.0) I get a webpage giving me a standard Proxy authorization required > message instead of the page I'm looking for: > Proxy authorization required > Username authentication is required for using this proxy. Either your > browser does not perform proxy authorization, or your authorization has > failed. > > I wondered whether it was that specific server so I tried with python.org > and got the same message. > Both systems use the same dialup ISP connection, and as far as I know there > certainly is no Proxy associated with either system. I have never had to do > anything proxy associated during any setup process, and when I grab that > file with IE5 it works like a charm. > > Any suggestions? I wasn't really sure what info might be relevant, so I may > not have provided everything a diagnostician might need. I don't even > really know where to look.... > > Looking for help (again... sigh), > > Mark > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From randrews@planhouse.com Fri May 4 17:36:50 2001 From: randrews@planhouse.com (Rob Andrews) Date: Fri, 4 May 2001 11:36:50 -0500 Subject: [Tutor] urlretrieve In-Reply-To: <004101c0d4b6$0314b900$e9b8c28e@anonymous> Message-ID: <001801c0d4b8$6b9d0f20$de00a8c0@planhouse5> I've been trying to reproduce your error on the most similar machine I can find, which is running 98SE and Python 2.1. So far, it works like a breeze here. Rob -----Original Message----- From: Mark A. Tobin [mailto:mtobin@attcanada.net] Sent: Friday, May 04, 2001 11:20 AM To: randrews@planhouse.com Cc: tutor@python.org Subject: Re: [Tutor] urlretrieve Rob, thanks for your prompt reply. I don't have Netscape installed on that system, however I took the advice anyway and checked the Internet Options that IE5 employs. Other than thinking it was connected using a LAN it was setup fine. All the proxy options were cleared. Just to be safe I changed the LAN to dialup and retested with the same result. Do the options in there affect how python connects to servers? Wouldn't they affect IE5's ability to grab the page as well? Any other ideas? I'm completely at a loss... Mark ----- Original Message ----- From: "Rob Andrews" To: "'Mark A. Tobin'" ; Sent: Friday, May 04, 2001 11:45 AM Subject: RE: [Tutor] urlretrieve > Are you using Netscape when you encounter the problem? If so, look under > Edit>Preferences. I think that under this you will find Advanced>Proxies and > may find that it expects a proxy now for some reason. There are a number of > somewhat rare reasons this can happen. If it is the case, you can easily > enough set it straight from there. > > Rob > > -----Original Message----- > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of > Mark A. Tobin > Sent: Friday, May 04, 2001 10:32 AM > To: tutor@python.org > Subject: [Tutor] urlretrieve > > > Hi again, > first I want to thank everybody who helped explain the whole self thing as > it has to do with classes, I think I'm slowly getting the idea. > second I'm having a problem with urlretrieve() and I'm not even sure where > the problem resides. Maybe some of you python/windows people out there > might be able to help. > I'm running two systems both Win95, one runs 1.5.2, and one 2.0. Both > systems are similarly configured, at least as far as I know to look. When I > do this: > >>>from urllib import urlretrieve > >>>urlretrieve("http://www.ihrg.com/nssnet/default.htm", "test.htm") > ('test.htm', ) > it looks like it worked right? > well on the system using 1.5.2 it does work, I get that webpage, intact, > saved in the appropriate file. However, on the other system (running python > 2.0) I get a webpage giving me a standard Proxy authorization required > message instead of the page I'm looking for: > Proxy authorization required > Username authentication is required for using this proxy. Either your > browser does not perform proxy authorization, or your authorization has > failed. > > I wondered whether it was that specific server so I tried with python.org > and got the same message. > Both systems use the same dialup ISP connection, and as far as I know there > certainly is no Proxy associated with either system. I have never had to do > anything proxy associated during any setup process, and when I grab that > file with IE5 it works like a charm. > > Any suggestions? I wasn't really sure what info might be relevant, so I may > not have provided everything a diagnostician might need. I don't even > really know where to look.... > > Looking for help (again... sigh), > > Mark > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From bsass@freenet.edmonton.ab.ca Fri May 4 18:33:56 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Fri, 4 May 2001 11:33:56 -0600 (MDT) Subject: [Tutor] Re: [Tutor]-Python figuring out groups--setting up a table in GUI In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D736@mbtlipnt02.btlabs.bt.co.uk> Message-ID: from the forgotten in postponed-msgs file... On Tue, 1 May 2001 alan.gauld@bt.com wrote: > As for Blackadder it is a commercial product but I don't > know how useful the GUI builder support is. (I'm not even > 100% sure it has any!) I would imagine ('cause I've only looked at the unix PyQt, free) you would at least get Qt-Designer and pyuic (to generate PyQt code, uic generates C++). Qt-Designer "feels right" and works well, the python produced by pyuic is clean and readable. - Bruce From virketis@fas.harvard.edu Fri May 4 19:56:55 2001 From: virketis@fas.harvard.edu (Pijus Virketis) Date: Fri, 04 May 2001 14:56:55 -0400 Subject: [Tutor] an executable for Macs In-Reply-To: Message-ID: <200105041852.f44IqS715690@smtp4.fas.harvard.edu> Hi, I've writen a little script for statistical analysis of tree phylogeny data. Unfortunately, the guys who'll be using it are card-carrying computer-ignorant descriptive botanists who love Macs. So, I need to convert the script to an executable. Does the py2exe.py module, which somebody had mentioned a few emails ago, work for this task? Do I need something special for Macs? Thank you! Pijus ---------------------------------------------------------------------------- ------------------- Please have a look at my weblog at www.fas.harvard.edu/~virketis. From johnp@reportlab.com Fri May 4 20:02:19 2001 From: johnp@reportlab.com (John Precedo) Date: Fri, 4 May 2001 20:02:19 +0100 Subject: [Tutor] an executable for Macs In-Reply-To: <200105041852.f44IqS715690@smtp4.fas.harvard.edu> Message-ID: > Hi, Howdy! > I've written a little script for statistical analysis of tree phylogeny > data....I need to convert the script to an executable....Do I need > something special for Macs? If you can get your hands on a Mac equipped with Python, it comes with a utility called 'Build Application'. It should be in the same folder as the main Python Interpretor and Python IDE programs. Copy your script file onto the Mac, drop it onto the 'build application' icon and voila! Short period while a window pops up, loads of text churns out and you see another icon on your desktop - your new application. One caveat - I have no idea how well this works for serious scripts. The only times I have used it are on simple stuff not much more complex than 'hello world'. Another caveat - my Mac stays at home while I have to go out to work, so this has been from memory. Hope this helps. John -- John Precedo (johnp@reportlab.com) Junior Developer Reportlab, Inc (http://www.reportlab.com) From deirdre@deirdre.net Fri May 4 21:11:31 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Fri, 4 May 2001 13:11:31 -0700 Subject: [Tutor] an executable for Macs In-Reply-To: <200105041852.f44IqS715690@smtp4.fas.harvard.edu> References: <200105041852.f44IqS715690@smtp4.fas.harvard.edu> Message-ID: >I've writen a little script for statistical analysis of tree phylogeny >data. Unfortunately, the guys who'll be using it are card-carrying >computer-ignorant descriptive botanists who love Macs. So, I need to >convert the script to an executable. Does the py2exe.py module, which >somebody had mentioned a few emails ago, work for this task? Do I need >something special for Macs? What John said -- there's an analogous process, but a different tool. And be careful what you say about us Mac folks, 'kay? :) -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From vlindberg@verio.net Sat May 5 01:11:09 2001 From: vlindberg@verio.net (VanL) Date: Fri, 04 May 2001 18:11:09 -0600 Subject: [Tutor] Most efficient representation of a tree? Message-ID: <3AF3451D.BCBAF3F3@verio.net> Hello, What would be the most efficient representation of a tree? In this tree, each node could have an arbitrary number of children. I also wanted to be able to order the children so I can traverse the trees in different ways (preorder, postorder, etc). Anyway, at least a leftmost-child, right-sibling ordering. I was considering two options: 1. A modification of Guido's adjacency-list implementation of a graph (see http://www.python.org/doc/essays/graphs.html). After all, this sort of tree is just special case sparse graph. 2. A node class with a parent link and a list of links to each child -- essentially a generalization of the linked list class that I posted here a month ago. Any other options? Does anyone have any idea how these would compare in terms of speed and execution resources? Thanks, VanL From julieta_rangel@hotmail.com Sat May 5 01:14:22 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Fri, 04 May 2001 19:14:22 -0500 Subject: [Tutor] inserting items into a list Message-ID: Daniel, Great suggestion! Everyday I learn something new about programming. I had no idea I could do it. I only thought about it because it would be easy for me not having to combine like terms in the multiplication of polynomials. I knew that if I did it this way I would not have to combine like terms, which would take me at least a day to figure out how to do it [you know what a slow poke I am at this :)]. >From: Daniel Yoo >To: Julieta Rangel >CC: tutor@python.org >Subject: Re: [Tutor] inserting items into a list >Date: Thu, 3 May 2001 22:41:33 -0700 (PDT) > >On Thu, 3 May 2001, Julieta Rangel wrote: > > > [3,0,6], then [1,0,2] and finally [2,0,4]. I need to find a way to >insert 3 > > zeroes at the end of list [2,0,4]; 1 zero at the beginning and two at >the > > end of [3,0,6]; 2 zeroes a the beginning and one at the end of [1,0,2], >and > > finally 3 zeroes at the beginning of [2,0,4]. This way the new lists >would > > look like: > > > > [2,0,4,0,0,0] > > [0,3,0,6,0,0] > > [0,0,1,0,2,0] > > [0,0,0,2,0,4] > > > > and it would be just a matter of adding those lists to figure out the > > result: 2 + 3x + 5x^2 + 8x^3 + 2x^4 + 4x^5. As you can see from the > > subject, my problem is inserting those zeroes at the specific locations. > > Can you help me? > > >How about something like this? > >### >def makeZeroPaddedList(mylist, position, length): > """This function should take mylist, and splice it into > a list of zeros at a specific location.""" > newlist = [0] * length > newlist[position:position + len(mylist)] = mylist > return newlist >### > > >Let's test it out on the interpreter: > >### > >>> makeZeroPaddedList([1, 2, 3], 0, 10) >[1, 2, 3, 0, 0, 0, 0, 0, 0, 0] > >>> makeZeroPaddedList([1, 2, 3], 1, 10) >[0, 1, 2, 3, 0, 0, 0, 0, 0, 0] > >>> makeZeroPaddedList([1, 2, 3], 2, 10) >[0, 0, 1, 2, 3, 0, 0, 0, 0, 0] > >>> makeZeroPaddedList([1, 2, 3], 3, 10) >[0, 0, 0, 1, 2, 3, 0, 0, 0, 0] > >>> makeZeroPaddedList([1, 2, 3], 4, 10) >[0, 0, 0, 0, 1, 2, 3, 0, 0, 0] >### > > >The idea is to make up a list that's filled only with zeros, and then plop >our original list into it. We can control both the position of the >plopping, and the length of the resulting list. > >Hope this helps! > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From sheila@thinkspot.net Sat May 5 04:27:27 2001 From: sheila@thinkspot.net (Sheila King) Date: Fri, 04 May 2001 20:27:27 -0700 Subject: [Tutor] Python book suggestion please In-Reply-To: References: Message-ID: <3065B5B7339@kserver.org> On Fri, 04 May 2001 06:28:06 -0000, "Learn Python" wrote about [Tutor] Python book suggestion please: :I'm looking to buy a good / probably the best reference :book available right now in the market. I checked out :a few titles and arrived at the follwing titles: : :1. Programming Python 2nd edition (orielly) :2. Python programmer's refernce (Insider Press)..by Beazely ( this is not :uptodate i guess since it does'nt cover 2.0) I have these three Python books: Programming Python, 2nd ed. Mark Lutz. Assumes that you already know Python. If you felt really comfortable after working through the Tutorial that comes with the standard distribution, and were already up and writing scripts, this might be a good book. Not concise. But, has an index. Lots of examples. Lots. Huge book. Core Python Programming. Wesley Chun. Assumes you already know some other high level programming language. Starts with a nice overview chapter, and then has a chapter on each topic which goes into more detail. My favorite of the three I have. Not as big as Programming Python, 2nd ed, and the print is larger. Lighter to read. Many examples. Quick Python. Daryl Harms and Kenneth McDonald. An extremely concise overview for someone who already knows how to program in another language. Small and compact. I haven't looked at this one quite as much. A fair number of examples. Most examples are snippets, rather than full programs. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From LloydJ@missouri.edu Sat May 5 04:56:42 2001 From: LloydJ@missouri.edu (Lloyd, Jamie) Date: Fri, 4 May 2001 22:56:42 -0500 Subject: [Tutor] problem with cgi Message-ID: <44D2ED0AC0121146BF01366481060EBE60714D@umc-mail02.missouri.edu> #!/usr/local/bin/env python print "Content-type: text/html\n\n" print "" print "" print "Thank you for using my first python/cgi program!" print "Just enter your name in the text field." print "" this is what I have so far, but it's giving me an 500 Internal server error. Could someone please tell me what is wrong? I could have swore that this would work?!?!? From sheila@thinkspot.net Sat May 5 05:04:29 2001 From: sheila@thinkspot.net (Sheila King) Date: Fri, 04 May 2001 21:04:29 -0700 Subject: [Tutor] problem with cgi In-Reply-To: <44D2ED0AC0121146BF01366481060EBE60714D@umc-mail02.missouri.edu> References: <44D2ED0AC0121146BF01366481060EBE60714D@umc-mail02.missouri.edu> Message-ID: <32824986A94@kserver.org> On Fri, 4 May 2001 22:56:42 -0500, "Lloyd, Jamie" wrote about [Tutor] problem with cgi: :#!/usr/local/bin/env python : :print "Content-type: text/html\n\n" :print "" :print "" :print "Thank you for using my first python/cgi program!" :print "Just enter your name in the text field." :print "" : :this is what I have so far, but it's giving me an 500 Internal server error. :Could someone please tell me what is wrong? I could have swore that this :would work?!?!? Your Python script looks fine. Are you sure you have the permissions set correctly? What type of operating system are you running this on? Is the web server configured to run python scripts? If it is a Linux/Unix type server, are the permissions set so that it is an executable file? Did you upload it in ASCII mode to the server? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From Mark A. Tobin" Message-ID: <005c01c0d519$f9155f40$e9b8c28e@anonymous> All evening I've been puzzling over this little problem. I really wanted to know where the root of the problem was. Python? My system? My ISP? So I uninstalled Python 2.0 from the suspect system and installed 1.5.2 onto it just to see what would happen. Lo and behold it works! No more Proxy authentication error! So from my point of view everything is fine, I can probably load 2.1 and things will be fine, or if not I have no big problem with sticking with 1.5.2. However I would like any suggestions as to why this problem could be. It seems rather odd that 2.0's urllib.urlretrieve() method would cause a problem where 1.5.2's seems to work perfectly.... Mark ----- Original Message ----- From: "Rob Andrews" To: "'Mark A. Tobin'" ; Cc: Sent: Friday, May 04, 2001 12:36 PM Subject: RE: [Tutor] urlretrieve > I've been trying to reproduce your error on the most similar machine I can > find, which is running 98SE and Python 2.1. So far, it works like a breeze > here. > > Rob > From jsc@rock-tnsc.com Sat May 5 21:21:10 2001 From: jsc@rock-tnsc.com (Jethro Cramp) Date: Sat, 5 May 2001 12:21:10 -0800 Subject: [Tutor] Unpickling a Pickled Object In-Reply-To: References: Message-ID: <01050512211000.00932@jsclaptop> On Friday 04 May 2001 12:19 am, Learn Python wrote: > hi Jethro, > > c'd you please tell why you think the __init__ s'd'nt be called? > If i'm doing some initialisation in __init__ > whch in turn will be used by other methods then the unpickling w'd'nt > be of much use right? > my code might fail bcos certain things did'nt get initialized. > Do we have a > private void readObject() java equivalent in python? which w'd > automatically get called when we "deserialize" the object / in this case > "unpickle". Then we can probably initialize some stuff there? > > karthik > Dear Karthik, As I understand it when you pickle an object you are infact saving the object's state. The reason I asked (and hoped that _init_ isn't called when I unpickle an object) is that in the class I was designing I want to set an IsValid property to false (because when the class is instantiated it will be in an invalid state) and a list of properties that are an invalid state. When the object gets serialized it can either be in a valid or invalid state, and a list of the properties that are still invalid are serialized with it. When the object is unpickled (in my mind) it should be in the same state as when it was pickled. Running __init__ when it is unserialised might change that. I didn't want to write code in __init__ to check for validity. Not a big deal to implement, but I am LAZY, after all ;). Sorry I don't know anything about JAVA and I'm not much of a programmer so I can't answer your question about readObject(). Maybe someone wiser on this list can give you an answer Jethro From bdupire@seatech.fau.edu Sat May 5 05:40:37 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Sat, 05 May 2001 00:40:37 -0400 Subject: [Tutor] Most efficient representation of a tree? References: <3AF3451D.BCBAF3F3@verio.net> Message-ID: <3AF38445.9652A09A@seatech.fau.edu> I have to answer this one, as i am doing something very similar for my project... What i chose is kind of between Guido's implementation and yours... I have a node class with a parent link and a list of links to each child, as you did. But the node objects are stored in a dictionnary. key = , like Guido did. Actually, at the beginning, i have a node class with a parent variable (which indicates the name of the parent) and with a list of the children names.... I can't have a list of links to each child at the beginning since the node objects are not created simultaneously in my system. When all the nodes are created, i am doing a 'second pass' and i replace every node's name by its reference. (I hope you still follow me...i implement what is called a tree-dictionary.) In term of speed now, storing references to the nodes is quicker, because in the dictionary approach, Python has to compute the key of the hash table, from the name of the node to find this reference. Now on the 'resource side', it's not too bad. References are shorter than names. The reason why i use an object (instead of a tuple containing parent link and a list of links to each child), is that i need to store a lot more in my node, and i need methods too... My 'node' class is actually called a 'state' class. Now looking at the memory side. Actually when you run the Python interpreter (a Python process) on your computer it takes ...600 k- a few meg (depending on your program)... so you only care about memory if you want to create a LOT of nodes. If it's less than , let's say 100, really, you don't have to worry. A dictionary takes 24 bytes + 12* 2^n bytes where n= log2(n items) + 1 A class instance = 16 bytes + a dictionary A list = 16 bytes + 4 bytes for each item A tuple = list You are only concerned about memory, if, like me, you are running 10-20 python processes at a time, which are all dealing with nodes.... this begins to suck RAM...but anyway, buying memory is not so expensive now.../ or you can use MicroThreads... I am very concerned about time in my system, not about the number of nodes, which is low in my project (<50), so i think my approach is good :o). I lose time at first, fetching all these references in my dictionary, but this is done once, and not everytime at run-time, so it's much faster. If you want both.. memory and speed, do not implement nodes as objects, but as nested tuples, and store references to the next node, not names. If you want to know what i am using a Tree dictionary for, you can go to http://www.python9.org/p9-cdrom/22/index.htm BUT there's no code there... (too long..) Benoit VanL wrote: > Hello, > > What would be the most efficient representation of a tree? > In this tree, each node could have an arbitrary number of children. > I also wanted to be able to order the children so I can traverse the > trees in different ways (preorder, postorder, etc). Anyway, at least a > leftmost-child, right-sibling ordering. > > I was considering two options: > > 1. A modification of Guido's adjacency-list implementation of a graph > (see http://www.python.org/doc/essays/graphs.html). After all, this > sort of tree is just special case sparse graph. > > 2. A node class with a parent link and a list of links to each child -- > essentially a generalization of the linked list class that I posted here > a month ago. > > Any other options? > > Does anyone have any idea how these would compare in terms of speed and > execution resources? > > Thanks, > > VanL > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From julieta_rangel@hotmail.com Sat May 5 06:25:15 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sat, 05 May 2001 00:25:15 -0500 Subject: [Tutor] tables and dictionaries Message-ID: I'm trying to write a program that given a finite set (say, up to 30 elements) and a table,the program figures out whether the set is a group. I need to have the user enter the elements on the set and store them on a list. Once on this list, I want the user to enter a table, but for this, I need for python to pair each element with every element on the list so I can ask for the table. Let's say that the set consists of elements [e,a,b,ab]. I need to ask the user e*e=? a*e=? b*e=? ab*e=? e*a=? a*a=? b*a=? ab*a=? e*b=? a*b=? b*b=? ab*b=? e*ab=? a*ab=? b*ab=? ab*ab=? Since I don't know what the set will consist of, I need to find a way so that once the user enters the set, the computer pairs the elements together as I did above, asks for the required input and stores it in a dictionary. Can this be done? If so, how? If this can be done, it would be easier to check for the four properties of a group[closure under binary operation, associativity : a*(a*b)=(a*a)*b; identity and inverses). I know it is a tedious task, but for now I'm interested in finding out whether it is possible to have the computer pair up the elements in the set, and if so, how? Any suggestions or help? Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From sheila@thinkspot.net Sat May 5 06:48:35 2001 From: sheila@thinkspot.net (Sheila King) Date: Fri, 04 May 2001 22:48:35 -0700 Subject: [Tutor] tables and dictionaries In-Reply-To: References: Message-ID: <38757F21A42@kserver.org> On Sat, 05 May 2001 00:25:15 -0500, "Julieta Rangel" wrote about [Tutor] tables and dictionaries: :I need to find a way so :that once the user enters the set, the computer pairs the elements together :as I did above, asks for the required input and stores it in a dictionary. :Can this be done? If so, how? Yes, this can be done. if you have the following objects already defined... list = [e,a,b,ab] table = {} (Note: e, a, b, and ab have to already be objects. It might be easiest to let them be strings and define them as e = 'e' and so forth...) I suggest a nested loop structure, like this... for firstElt in list: for secondElt in list: table[ (firstElt, secondElt) ] = None What the above code does is, select an element in list. For example, e. Then, holding 'e' constant as the first Element (the first "for" loop), it goes into a second for loop on the second Element. So, while "e" is held fixed as the first element, it will go through the list for the second element, and create the following tuples: (e, e) (e, a) (e, b) (e, ab) After it has done that, it will switch to another element in the list for the firstElement. Possibly 'a'. It will hold 'a' fixed on the first for-loop and on the second for loop, go through all the elements in the list to get the second element, getting these tuples: (a, e) (a, a) (a, b) (a, ab) and so on. The first for-loop will also go through b and ab as the first element. The statement table[ firstElt, secondElt ] = None puts a key in the dictionary "table", that is a tuple (like one of the example tuples listed above), and assigns it the value "None", which is a special value in Python, meaning "no value". I think this is the best value you can assign in the dictionary "table", while you are generating the ordered pairs, since you plan on asking the user to input the values for the table later. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From tutor@python.org Sat May 5 06:56:11 2001 From: tutor@python.org (Tim Peters) Date: Sat, 5 May 2001 01:56:11 -0400 Subject: [Tutor] tables and dictionaries In-Reply-To: Message-ID: [Julieta Rangel] > I'm trying to write a program that given a finite set (say, up to 30 > elements) and a table, the program figures out whether the set is a > group. I need to have the user enter the elements on the set and > store them on a list. Once on this list, I want the user to enter > a table, but for this, I need for python to pair each element with > every element on the list so I can ask for the table. Hmm! For a set with 30 elements, that's 30*30 == 900 "products". So you may want to read this information from a file instead. > Let's say that the set consists of elements > [e,a,b,ab]. I need to ask the user > > e*e=? a*e=? b*e=? ab*e=? > e*a=? a*a=? b*a=? ab*a=? > e*b=? a*b=? b*b=? ab*b=? > e*ab=? a*ab=? b*ab=? ab*ab=? > > Since I don't know what the set will consist of, I need to find a way > so that once the user enters the set, the computer pairs the elements > together as I did above, asks for the required input and stores it in > a dictionary. Can this be done? Yes, and quite easily (if you know how ) -- I'll attach a small program. Here's a sample run, where to *try* to make it clearer I've artificially added "<>" brackets around the input I typed in; everything else is program output: Enter comma-separated list of elements, like a,b,c: a*a=? a*b=? b*a=? Oops! c is not in ['a', 'b'] -- try again. b*a=? b*b=? a * a = a a * b = b b * a = b b * b = a > If so, how? If this can be done, it would be easier to check for > the four properties of a group[closure under binary operation, Note that the program above rejected my attempt to enter c, so the *input* routine ensures closure. > associativity : a*(a*b)=(a*a)*b; identity and inverses). > ... These are, of course, harder to check. I wouldn't call it "tedious", though! It seems like a very nice exercise for learning how to use loops and logic. oh-ok-it's-tedious-ly y'rs - tim import string elts = raw_input("Enter comma-separated list of elements, like a,b,c: ") elts = string.split(elts, ",") product = {} for x in elts: for y in elts: prompt = "%s*%s=? " % (x, y) need_good_result = 1 while need_good_result: z = raw_input(prompt) if z in elts: need_good_result = 0 else: print "Oops!", z, "is not in", elts, "-- try again." product[x, y] = z # Display the table. items = product.items() items.sort() for (x, y), z in items: print x, "*", y, "=", z From sheila@thinkspot.net Sat May 5 07:05:51 2001 From: sheila@thinkspot.net (Sheila King) Date: Fri, 04 May 2001 23:05:51 -0700 Subject: [Tutor] tables and dictionaries In-Reply-To: <38757F21A42@kserver.org> References: <38757F21A42@kserver.org> Message-ID: <397222C3DEA@kserver.org> On Fri, 04 May 2001 22:48:35 -0700, Sheila King wrote about Re: [Tutor] tables and dictionaries: : :I suggest a nested loop structure, like this... : :for firstElt in list: : for secondElt in list: : table[ (firstElt, secondElt) ] = None Here's a thought: To help you better see what is going on in a nested looping structure like the one above (where one loop is inside another), try this piece of code, and see what it does: >>> for firstNum in range(2,5): ... for secondNum in range(11,16): ... print firstNum, ' + ', secondNum, ' = ', firstNum + secondNum ... print "inside loop ended" ... -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From julieta_rangel@hotmail.com Sat May 5 07:39:09 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sat, 05 May 2001 01:39:09 -0500 Subject: [Tutor] tables and dictionaries Message-ID: Thanks for your suggestion and your program. As you might remember, I'm new at programming, and eventhough I have a good reference book, it is not easy to do it all alone. Sometimes I can read a section from the book until I'm blue in the face and still not understand it. The thing is that I'm a hands on learner, so I learn by example, and eventhough the book has examples to go along with the explanations, it is still difficult because sometimes the examples are not relevant or meaningful to me or might not answer all of my questions. Since I don't have anyone to show me in an example what the book is trying to say, it is very difficult for me to learn it. With the example you gave me I learned more than I would have learnt if I had spend an entire day reading about nested loops. Thank you so very much. Julieta >From: Sheila King >To: tutor@python.org >CC: "Julieta Rangel" >Subject: Re: [Tutor] tables and dictionaries >Date: Fri, 04 May 2001 23:05:51 -0700 > >On Fri, 04 May 2001 22:48:35 -0700, Sheila King >wrote >about Re: [Tutor] tables and dictionaries: > >: >:I suggest a nested loop structure, like this... >: >:for firstElt in list: >: for secondElt in list: >: table[ (firstElt, secondElt) ] = None > >Here's a thought: > >To help you better see what is going on in a nested looping structure like >the >one above (where one loop is inside another), try this piece of code, and >see >what it does: > > >>> for firstNum in range(2,5): >... for secondNum in range(11,16): >... print firstNum, ' + ', secondNum, ' = ', firstNum + secondNum >... print "inside loop ended" >... > >-- >Sheila King >http://www.thinkspot.net/sheila/ >http://www.k12groups.org/ > > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From deirdre@deirdre.net Sat May 5 08:34:35 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Sat, 5 May 2001 00:34:35 -0700 Subject: Fwd: [Tutor] tables and dictionaries In-Reply-To: References: Message-ID: >In a message dated 5/5/01 12:41:19 AM Mountain Daylight Time, >julieta_rangel@hotmail.com writes: > >>tutor-admin@python.org >> > > > >take me of this .... Sorry about that...the violation of TOS has been reported to AOL and the offender's posts have been held. While he was told that every email contained unsubscribe instructions, his response was simple vulgarity. -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From LloydJ@missouri.edu Sat May 5 09:41:36 2001 From: LloydJ@missouri.edu (Lloyd, Jamie) Date: Sat, 5 May 2001 03:41:36 -0500 Subject: [Tutor] how to add multiple strings.. Message-ID: <44D2ED0AC0121146BF01366481060EBE607152@umc-mail02.missouri.edu> Here is my beginning html code.. Jamie's hello program
Jamie's hello program

Mr Ms

Please enter your name:

and this is my python script for doing it.. #!/usr/bin/python import cgi, os, sys print "Content-type: text/html\n\n" print "" form = cgi.FieldStorage() name = form["name"].value sir = form["sir"].value if not form.has_key("name") or form["name"].value == "" print "
You did not enter your name, click to go back!" else: print "

Hello " + sir + ". " + name + "

" print "" The script prints the name, but it does not print Mr. or Ms. before the name even though you select the bullet in the html code? Could someone please help me? Thanks in advance! Jamie From kauphlyn@speakeasy.org Sat May 5 12:56:54 2001 From: kauphlyn@speakeasy.org (Daniel Coughlin) Date: Sat, 5 May 2001 04:56:54 -0700 (PDT) Subject: [Tutor] how to add multiple strings.. In-Reply-To: <44D2ED0AC0121146BF01366481060EBE607152@umc-mail02.missouri.edu> Message-ID: html snipped -- > and this is my python script for doing it.. > > #!/usr/bin/python > > import cgi, os, sys > > print "Content-type: text/html\n\n" > print "" > form = cgi.FieldStorage() > name = form["name"].value > sir = form["sir"].value > if not form.has_key("name") or form["name"].value == "" aside from not including the colon here ^ (:) your script works fine on my computer. I am running this on win2k ie 5.5. perhaps you need to refresh your browser or empty the cache? as i ve found sometimes tweaks i make to dont get updated unless i clear the cache. Hope this helps. Daniel From learnpython@hotmail.com Sat May 5 14:46:24 2001 From: learnpython@hotmail.com (Learn Python) Date: Sat, 05 May 2001 13:46:24 -0000 Subject: [Tutor] Unpickling a Pickled Object Message-ID: hi jethor, Okay according to your requirements it w'd be a problem if init() gets called. As someone has already posted __init__() does'nt get called in python 2.0...it does'nt get called in Java either. rgds, karthik. >From: Jethro Cramp >Reply-To: jsc@rock-tnsc.com >To: "Learn Python" >CC: tutor@python.org >Subject: Re: [Tutor] Unpickling a Pickled Object >Date: Sat, 5 May 2001 12:21:10 -0800 > >On Friday 04 May 2001 12:19 am, Learn Python wrote: > > hi Jethro, > > > > c'd you please tell why you think the __init__ s'd'nt be called? > > If i'm doing some initialisation in __init__ > > whch in turn will be used by other methods then the unpickling w'd'nt > > be of much use right? > > my code might fail bcos certain things did'nt get initialized. > > Do we have a > > private void readObject() java equivalent in python? which w'd > > automatically get called when we "deserialize" the object / in this case > > "unpickle". Then we can probably initialize some stuff there? > > > > karthik > > >Dear Karthik, > >As I understand it when you pickle an object you are infact saving the >object's state. The reason I asked (and hoped that _init_ isn't called when >I >unpickle an object) is that in the class I was designing I want to set an >IsValid property to false (because when the class is instantiated it will >be >in an invalid state) and a list of properties that are an invalid state. >When >the object gets serialized it can either be in a valid or invalid state, >and >a list of the properties that are still invalid are serialized with it. >When >the object is unpickled (in my mind) it should be in the same state as when >it was pickled. Running __init__ when it is unserialised might change that. >I didn't want to write code in __init__ to check for validity. Not a big >deal >to implement, but I am LAZY, after all ;). > >Sorry I don't know anything about JAVA and I'm not much of a programmer so >I >can't answer your question about readObject(). Maybe someone wiser on this >list can give you an answer > >Jethro _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From learnpython@hotmail.com Sat May 5 14:53:22 2001 From: learnpython@hotmail.com (Learn Python) Date: Sat, 05 May 2001 13:53:22 -0000 Subject: [Tutor] Python book suggestion please Message-ID: thanks, i w'd probably try Core python progarmming. karthik. >Programming Python, 2nd ed. Mark Lutz. Assumes that you already know >Python. >If you felt really comfortable after working through the Tutorial that >comes >with the standard distribution, and were already up and writing scripts, >this >might be a good book. Not concise. But, has an index. Lots of examples. >Lots. >Huge book. > >Core Python Programming. Wesley Chun. Assumes you already know some other >high >level programming language. Starts with a nice overview chapter, and then >has >a chapter on each topic which goes into more detail. My favorite of the >three >I have. Not as big as Programming Python, 2nd ed, and the print is larger. >Lighter to read. Many examples. > >Quick Python. Daryl Harms and Kenneth McDonald. An extremely concise >overview >for someone who already knows how to program in another language. Small and >compact. I haven't looked at this one quite as much. A fair number of >examples. Most examples are snippets, rather than full programs. > >-- >Sheila King >http://www.thinkspot.net/sheila/ >http://www.k12groups.org/ > _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. From julieta_rangel@hotmail.com Sat May 5 20:28:09 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sat, 05 May 2001 14:28:09 -0500 Subject: [Tutor] stopping a loop Message-ID: Hello, Here I am, bugging you guys ...AGAIN!. As some of you might remember, I'm trying to write a program that determines whether a set is a group or not. That is, given a finite set and a table, check for closure, associativity, and make sure all elements in set have inverses and identity elements. This is what I have so far: import string set = raw_input("Enter the elements of the set separated by a comma,ie, a,b,c: ") set = string.split(set, ",") op = raw_input("Enter the binary operator sign, ie, * : ") product = {} for x in set: for y in set: prompt ="%s %s %s = ? "%(x,op,y) z= raw_input(prompt) product[x,y] = z print " " #Display the table items = product.items() items.sort() for(x,y),z in items: print x,op,y, " = ",z I figure that if the user enters an element (when asked for the table values), that is not in the set, there is no point in having the computer ask for the remainder of the table because the set is not a group. I tried inserting an "if" clause saying that if "z" is not in the set, print "The set is not a group", and break the loop. The if clause worked well, if I entered an element (when asked for the table values) that was not in the set, the computer would inform me that the set is not a group because closure fails; however, the result was not what I was looking for, the computer would keep asking me for the rest of the table values. I read that to break a loop I must insert a break statement, but I could not figure out where to place it. I tried placing it in different places, but it wouldn't work. Can anyone help me stop the loop as soon as a table value that is not in the set is entered? The section in my book about breaking loops is not very clear, at least not to me, so that's why you have me here, asking dumb questions ...AGAIN. julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From dyoo@hkn.eecs.berkeley.edu Sat May 5 21:37:37 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sat, 5 May 2001 13:37:37 -0700 (PDT) Subject: [Tutor] stopping a loop In-Reply-To: Message-ID: On Sat, 5 May 2001, Julieta Rangel wrote: > Here I am, bugging you guys ...AGAIN!. As some of you might remember, I'm Don't worry about it; we're tough, we can handle it. *grin* Seriously, you don't need to apologize about asking questions; just have fun, play around with Python, and talk to us when things look weird. We're all here voluntarily, so if it makes you feel better, we should be apologizing to you for writing such boring, long sentences about feeling unjustifiably embarrased about hurting our feelings about a difficult subject that's quite enormously unintuitive at the beginning but gets easier as you learn more about it. > for x in set: > for y in set: > prompt ="%s %s %s = ? "%(x,op,y) > z= raw_input(prompt) > > product[x,y] = z > print " " > set, the computer would inform me that the set is not a group because > closure fails; however, the result was not what I was looking for, the > computer would keep asking me for the rest of the table values. I read that > to break a loop I must insert a break statement, but I could not figure out > where to place it. I tried placing it in different places, but it wouldn't Using break is the right idea; however, break will pull us out of any innermost loop: because we're in a nested loop though, we're still within the body of the outside loop when we do a break. Here's an example that shows this behavior: ### >>> for x in range(5): ... for y in range(5): ... print x,y ... if y == 0: break ... 0 0 1 0 2 0 3 0 4 0 ### So even though we did a break, we didn't break out of the outermost loop. If we want to break out of the whole loop, one approach we can use is to "cascade" the break, so that we continue breaking until we're out. ### >>> unsuccess = 0 >>> for x in range(5): ... for y in range(5): ... print x, y ... if y == 0: ... unsuccess = 1 ... break ... if unsuccess == 1: ... break ... 0 0 ### Domino effect. Another way to organize this is to have your Cayley table input routine be itself a small function. For example, we can write a small helper function like this: ### def getCayleyTable(op, set): product = {} for x in set: for y in set: prompt ="%s %s %s = ? "%(x,op,y) z= raw_input(prompt) product[x,y] = z if z not in set: return product # jump out entirely from the function print return product ### Writing a helper function might be good because it allows us to concentrate on a small part of your program. Because it's a complete function, we can do testing on it, even if we're not done with the rest of the program yet. For example, if we have the getCayleyTable function written above, we might be curious to see if it works at all: ### >>> mytable = getCayleyTable('+', [0, 1, 2]) 0 + 0 = ? 0 >>> mytable {(0, 0): '0'} >>> mytable = getCayleyTable('+', ['0', '1', '2']) 0 + 0 = ? 0 0 + 1 = ? 1 0 + 2 = ? 2 1 + 0 = ? 1 1 + 1 = ? 2 1 + 2 = ? 0 2 + 0 = ? 2 2 + 1 = ? 0 2 + 2 = ? 1 >>> mytable {('1', '0'): '1', ('1', '1'): '2', ('1', '2'): '0', ('0', '0'): '0', ('0', '2'): '2', ('2', '1'): '0', ('0', '1'): '1', ('2', '0'): '2', ('2', '2'): '1'} ### Our first run through getCayleyTable shows us that we need to make sure our set elements are strings. This sort of testing becomes difficult when our programs balloon to larger sizes, so it's a good idea to get in the habit of organizing conceptually simple tasks into helper functions. Again, feel free to ask questions. Hope this helps! From julieta_rangel@hotmail.com Sun May 6 00:43:34 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sat, 05 May 2001 18:43:34 -0500 Subject: [Tutor] stopping a loop Message-ID: >>On Sat, 5 May 2001, Julieta Rangel wrote: > > > Here I am, bugging you guys ...AGAIN!. As some of you might remember, >I'm > >Don't worry about it; we're tough, we can handle it. *grin* > Thanks, I don't feel that awful anymore about being such a pest I followed your advice and did the following: import string def getCayleyTable(op,set): product = {} for x in set: for y in set: prompt = "%s %s %s = ? "%(x,op,y) print " " z = raw_input(prompt) product [x,y] = z if z not in set: print " " print "No need to go any further: your set is not a group" return product print " " items = product.items() items.sort() print " " print "your table is:" for(x,y),z in items: print " " print x,op,y, " = ",z print " " return product print " " set = raw_input("Enter the elements of the set separated by a comma,ie, a,b,c: ") set = string.split(set, ",") print " " op = raw_input("Enter the binary operator sign, ie, * : ") s = getCayleyTable( op,set ) print " " print s As you can see, my program runs the way I wanted it. Thanks for being so helpful (This includes everyone who has helped me all this time). Now I have to check for associativity, and I'm trying to figure out how I can do that. The idea is that given a set, say {e,a,b,ab}, and the table e*e=e a*e=a b*e=b ab*e=ab e*a=a a*a=e b*a=ab ab*a=b e*b=b a*b=ab b*b=e ab*b=a e*ab=ab a*ab=b b*ab=a ab*ab=e we can look for associativity by making all the possible combinations. That is, verify that e*(e*e)=(e*e)*e, a*(e*e)=(a*e)*e, and so on. To do this we would have to ask our dictionary for the table values and apply them to the elements on the set. What I mean is, say I want to verify that a*(a*ab)= (a*a)*ab I need to take every item (or the definition of my item) from my dictionary and combine it with every item on my set. We would need to consult our dictionary for the value of (a*ab) and (a*a). Once we get our values (b, and e respectively), then we would consult our dictionary once again to figure out what a*b equals to and what e*ab equals to so we can compare. As we can see, a*b=ab and e*ab= ab, therefore this particular combination works and we can move to the next one. So you can see it better, scroll down: a*(a*ab) and (a*a)*ab = a*( b ) =( e )*ab = ab = ab I know it is confusing, and maybe my wording is not explicit enough. If you don't understand what I'm trying to say e-mail me. Anyway, I'm working on this, and I'm assuming I will have to make another nested loop with my table values and my set. I have no idea if I'm on the right track. All I can do for now is think about how I could tell the computer to do this. Do you have any suggestions, comments, or why not, an answer ;-), e-mail me. >>> Julieta > > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From tutor@python.org Sun May 6 00:55:11 2001 From: tutor@python.org (Tim Peters) Date: Sat, 5 May 2001 19:55:11 -0400 Subject: [Tutor] stopping a loop In-Reply-To: Message-ID: [Julieta Rangel] > ... > Now I have to check for associativity, and I'm trying to figure out > how I can do that. > ... > we can look for associativity by making all the possible combinations. > That is, verify that e*(e*e)=(e*e)*e, a*(e*e)=(a*e)*e, and so on. Here's a hint: you want to verify that x*(y*z) == (x*y)*z for all x, y and z in your set. Earlier you wanted to build a table for all x and y in your set. The latter involved two variables and was solved with a doubly-nested loop. So the former, involving three variables, might be approached how? One more hint: If x, y and z are elements of your set, then the result of x*(y*z) is spelled how? Start with y*z: that's product[y, z] So x*(y*z) is product[x, product[y, z]] and (x*y)*z is ...? you're-closer-than-you-know-ly y'rs - tim From julieta_rangel@hotmail.com Sun May 6 02:24:52 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sat, 05 May 2001 20:24:52 -0500 Subject: [Tutor] stopping a loop Message-ID: Are you implying a tripple nested loop? meaning for x in set: for y in set: for z in set: if ['x',('y','z')] == [('x','y'),'z']: return associativity holds Is this what you mean? If I give the computer those commands, will it look for the definition on my dictionary? You see, I'm not sure how I'm supposed to tell the computer to look in the dictionary for these values and compare them. Any more hints, ideas, suggestions, comments, questions? Julieta >From: "Tim Peters" >Reply-To: >To: "Julieta Rangel" >CC: >Subject: RE: [Tutor] stopping a loop >Date: Sat, 5 May 2001 19:55:11 -0400 > >[Julieta Rangel] > > ... > > Now I have to check for associativity, and I'm trying to figure out > > how I can do that. > > ... > > we can look for associativity by making all the possible combinations. > > That is, verify that e*(e*e)=(e*e)*e, a*(e*e)=(a*e)*e, and so on. > >Here's a hint: you want to verify that x*(y*z) == (x*y)*z for all x, y and >z >in your set. Earlier you wanted to build a table for all x and y in your >set. The latter involved two variables and was solved with a doubly-nested >loop. So the former, involving three variables, might be approached how? > >One more hint: If x, y and z are elements of your set, then the result of >x*(y*z) is spelled how? Start with y*z: that's > > product[y, z] > >So x*(y*z) is > > product[x, product[y, z]] > >and (x*y)*z is ...? > >you're-closer-than-you-know-ly y'rs - tim > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From sheila@thinkspot.net Sun May 6 04:14:10 2001 From: sheila@thinkspot.net (Sheila King) Date: Sat, 05 May 2001 20:14:10 -0700 Subject: [Tutor] stopping a loop In-Reply-To: References: Message-ID: <11BDBDF5CF9@kserver.org> On Sat, 05 May 2001 20:24:52 -0500, "Julieta Rangel" wrote about RE: [Tutor] stopping a loop: :Are you implying a tripple nested loop? meaning :for x in set: : for y in set: : for z in set: : if ['x',('y','z')] == [('x','y'),'z']: : return associativity holds : :Is this what you mean? If I give the computer those commands, will it look :for the definition on my dictionary? You see, I'm not sure how I'm supposed :to tell the computer to look in the dictionary for these values and compare :them. Any more hints, ideas, suggestions, comments, questions? : :Julieta I'm not sure if Tim was implying a triply-nested loop, or not. It sounded kind of like it to me, too. However, a double-nested loop will do fine. The key is, you need to use your dictionary to look up the values of the operations. That is the key. That is why you built the dictionary in the first place. Note that dictionaries have keys and values. For example: >>> dict = {} >>> dict['a']='apple' >>> dict['b']='banana' >>> dict['c']='cat' >>> print dict.keys() ['b', 'c', 'a'] >>> print dict.values() ['banana', 'cat', 'apple'] >>> I can use a loop on a dictionary as follows: >>> for key in dict.keys(): ... print dict[key], " starts with ", key, "." ... banana starts with b . cat starts with c . apple starts with a . [Notice that it doesn't necessarily put them in order.] Anyhow, for your situation, You are getting your table and storing it in the variable s. So, you should try this: print s.keys() print s.values() for pair in s.keys(): print pair " maps to ", s[pair] Try this also: for pair in s.keys(): for elt in set: if s[pair]==elt: print pair, " maps to ", elt else: print pair, " does not map to ", elt I don't think you will want to use any of those in your actual program, but playing with those and watching them run should prove insightful (I hope). OK, I've since decided, that Tim is probably right. I bet you do want a triply nested loop. Hm. Interesting. Here is what you asked about: :Are you implying a tripple nested loop? meaning :for x in set: : for y in set: : for z in set: : if ['x',('y','z')] == [('x','y'),'z']: : return associativity holds This is close. But, I think you need to apply your table mapping. You called the table s, so: for x in set: for y in set: for z in set: if s[(x, s(y,z))] == s[(s[(x,y)],z)] print "for ", str(s[(x, s(y,z))]), " and ", str(s[(s[(x,y)],z)]) print "associativity holds\n" Well, this will (I hope) get you closer to where you want to go. You're not there yet, but you're getting there. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From tescoil@irtc.net Sun May 6 06:17:41 2001 From: tescoil@irtc.net (Tesla Coil) Date: Sun, 06 May 2001 00:17:41 -0500 Subject: [Tutor] Possible Useless Python Challenge. Message-ID: <3AF4DE75.770921E8@irtc.net> Wondering about this as a possible Useless Python Challenge. I'd feel a little guilty suggesting it, as I'm uncertain how difficult a task it is, but really, Gilbert Roulot is moreso to blame. ;) Roulot is the author of the Foks Linux KiSS viewer. On the homepage, http://perso.wanadoo.fr/issarlk/Foks/ Roulot lists among "Features and technical stuff" that Foks is "written in the GNU Sather language. The best language there is to write KiSS viewers (IMNSHO)!" It doesn't appear this has ever been demonstrated incorrect by a better KiSS viewer being written in Python--for that matter, any KiSS viewer being written in Python. A KiSS viewer could prove a somewhat larger app than would be considered "Useless Python," but it probably qualifies in that one would be writing it perhaps more to have it done in Python than need for the utility of Yet Another program with which to play paperdolls... KiSS data sets are bundled using LZH compression, if there's a module for that, I haven't located it. I suppose that a cel file decoder could be cooked up using Python Imaging Library, but I've no experience in that department at all. Other than that, I guess one is up against reading .cnf files generated by a variety of editors and sometimes written by hand. More introduction & file specs can be found at http://www2s.biglobe.ne.jp/~yav/kiss/indexe.html From dyoo@hkn.eecs.berkeley.edu Sun May 6 10:10:20 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 6 May 2001 02:10:20 -0700 (PDT) Subject: [Tutor] stopping a loop [cross product instead of nested loops] In-Reply-To: <11BDBDF5CF9@kserver.org> Message-ID: On Sat, 5 May 2001, Sheila King wrote: > On Sat, 05 May 2001 20:24:52 -0500, "Julieta Rangel" > wrote about RE: [Tutor] stopping a loop: > > :Are you implying a tripple nested loop? meaning > :for x in set: > : for y in set: > : for z in set: > : if ['x',('y','z')] == [('x','y'),'z']: > : return associativity holds > : > :Is this what you mean? If I give the computer those commands, will it look > :for the definition on my dictionary? You see, I'm not sure how I'm supposed > :to tell the computer to look in the dictionary for these values and compare > :them. Any more hints, ideas, suggestions, comments, questions? > : > :Julieta > > I'm not sure if Tim was implying a triply-nested loop, or not. It sounded kind of > like it to me, too. However, a double-nested loop will do fine. > > The key is, you need to use your dictionary to look up the values of the operations. > That is the key. That is why you built the dictionary in the first place. You might find the following definition useful: it's a way of producing the "cross" product of two lists: ### def cross(set1, set2): resulting_set = [] for s1 in set1: for s2 in set2: resulting_set.append( (s1, s2) ) return resulting_set ### One reason why the cross product is so useful is because, given any two lists, it can give back to us all possible pairs of those two lists, all in a nice list: ### >>> cross([1, 2, 3, 4], [1, 2, 3, 4]) [(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 1), (3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)] ### Or, more evocatively: ### >>> numbers = ['1', '2'] >>> cross(numbers, cross(numbers, numbers)) [('1', ('1', '1')), ('1', ('1', '2')), ('1', ('2', '1')), ('1', ('2', '2')), ('2', ('1', '1')), ('2', ('1', '2')), ('2', ('2', '1')), ('2', ('2', '2'))] ### By using the function above, you might not even need any nested loops in your own code. Hope this helps! From ppathiyi@cisco.com Sun May 6 10:29:13 2001 From: ppathiyi@cisco.com (Praveen Pathiyil) Date: Sun, 6 May 2001 14:59:13 +0530 Subject: [Tutor] stopping a loop Message-ID: <063c01c0d60f$037e3470$37ef87c0@ppathiyipc> This is a multi-part message in MIME format. ------=_NextPart_000_0639_01C0D63D.1D1E0670 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, I had one doubt while seeing the discussion about "stopping a = loop". Don't we have a "goto" statement in python ? Thanks, Praveen. ------=_NextPart_000_0639_01C0D63D.1D1E0670 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
        I had=20 one doubt while seeing the discussion about "stopping a = loop".
        = Don't we have=20 a "goto" statement in python ?
 
Thanks,
Praveen.
------=_NextPart_000_0639_01C0D63D.1D1E0670-- From dyoo@hkn.eecs.berkeley.edu Sun May 6 11:23:09 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 6 May 2001 03:23:09 -0700 (PDT) Subject: [Tutor] stopping a loop In-Reply-To: <063c01c0d60f$037e3470$37ef87c0@ppathiyipc> Message-ID: On Sun, 6 May 2001, Praveen Pathiyil wrote: > I had one doubt while seeing the discussion about "stopping a loop". > Don't we have a "goto" statement in python ? There is no goto. However, it appears that the exception-handling model in Python can be abused toward a similar effect: http://www.python.org/doc/FAQ.html#6.26 It's arguable if the idea of a goto is really "evil", but it does complicate matters enough that it's not a feature in Python. For amusement, here's a link to Edsgar Dijkstra's famous paper, "Goto's Considered Harmful": http://www.acm.org/classics/oct95/ It's quite short, and pretty nice to see that something written in 1968 still has staying power. From tim@johnsons-web.com Sun May 6 18:11:49 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 6 May 2001 09:11:49 -0800 Subject: [Tutor] How Do I enable TKinter Message-ID: <01050609170000.12427@bart.johnson.com> Hello All: I recently installed Python 2.0 on RH Linux 6.0 I compiled from "scratch". When I attempt to run a Python Module using TKinter: I get the following error Message: File "/usr/local/lib/python2.0/lib-tk/Tkinter.py", line 35, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter It appears to this 'ol c-dog that I haven't compiled in the tkinter module. If this is the problem, what config switch should I be using? I can't seem to find any reference to tkinter in configure.... TIA Tim From rob@jam.rr.com Sun May 6 17:34:35 2001 From: rob@jam.rr.com (rob@jam.rr.com) Date: Sun, 06 May 2001 11:34:35 -0500 Subject: [Tutor] How Do I enable TKinter References: <01050609170000.12427@bart.johnson.com> Message-ID: <3AF57D1B.D01136A@jam.rr.com> This may be considered blasphemous, depending on your perspective, but since it's a RedHat system, have you tried using RPM installation? Rob Tim Johnson wrote: > > Hello All: > I recently installed Python 2.0 on RH Linux 6.0 > I compiled from "scratch". > When I attempt to run a Python Module using TKinter: > I get the following error Message: > File "/usr/local/lib/python2.0/lib-tk/Tkinter.py", line 35, in ? > import _tkinter # If this fails your Python may not be configured for Tk > ImportError: No module named _tkinter > It appears to this 'ol c-dog that I haven't compiled in the tkinter module. > > If this is the problem, what config switch should I be using? > I can't seem to find any reference to tkinter in configure.... > TIA > Tim > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From kalle@gnupung.net Sun May 6 18:06:58 2001 From: kalle@gnupung.net (Kalle Svensson) Date: Sun, 6 May 2001 19:06:58 +0200 Subject: [Tutor] How Do I enable TKinter In-Reply-To: <01050609170000.12427@bart.johnson.com>; from tim@johnsons-web.com on Sun, May 06, 2001 at 09:11:49AM -0800 References: <01050609170000.12427@bart.johnson.com> Message-ID: <20010506190658.A12383@apone.network.loc> Sez Tim Johnson: > ImportError: No module named _tkinter > It appears to this 'ol c-dog that I haven't compiled in the tkinter module. > > If this is the problem, what config switch should I be using? > I can't seem to find any reference to tkinter in configure.... No wonder, there is none... The Python 2.0 build process is IMHO slightly less than optimal. This is a lot better in 2.1, though. Anyway, what you want is the Modules/Setup file. Run configure, then copy Modules/Setup.in (or Modules/Setup.dist? use the one that exists. :) to Modules/Setup and edit it. Then make and make install, as usual. All this is IIRC, it's been a while since I compiled 2.0. Peace, Kalle -- Email: kalle@gnupung.net | You can tune a filesystem, but you Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8) PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD [ Not signed due to lossage. Blame Microsoft Outlook Express. ] From tim@johnsons-web.com Sun May 6 21:46:52 2001 From: tim@johnsons-web.com (Tim Johnson) Date: Sun, 6 May 2001 12:46:52 -0800 Subject: [Tutor] How Do I enable TKinter References: <3AF57D1B.D01136A@jam.rr.com> Message-ID: <01050612493301.12427@bart.johnson.com> Hi Rob: On Sun, 06 May 2001, rob@jam.rr.com wrote: > This may be considered blasphemous, depending on your perspective, but > since it's a RedHat system, have you tried using RPM installation? Using RPMs doesn't conflict at all with my religious views. I guess I was just compiler-happy that particular day. :>) Actually, I am now in the process of getting the RPM. I'm hoping the package is compatible with rpm on rh 6.0 - that is not always the case, I have found - but we shall see. If not, I'm gonna upgrade to later RH soon. Thanks tj > Rob > > Tim Johnson wrote: > > > > Hello All: > > I recently installed Python 2.0 on RH Linux 6.0 > > I compiled from "scratch". > > When I attempt to run a Python Module using TKinter: > > I get the following error Message: > > File "/usr/local/lib/python2.0/lib-tk/Tkinter.py", line 35, in ? > > import _tkinter # If this fails your Python may not be configured for Tk > > ImportError: No module named _tkinter > > It appears to this 'ol c-dog that I haven't compiled in the tkinter module. > > > > If this is the problem, what config switch should I be using? > > I can't seem to find any reference to tkinter in configure.... > > TIA > > Tim > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > -- > > Useless Python! > If your Python is this useless, we need you. > http://www.lowerstandard.com/python/pythonsource.html From julieta_rangel@hotmail.com Mon May 7 01:34:50 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sun, 06 May 2001 19:34:50 -0500 Subject: [Tutor] [cross product instead of nested loops] Message-ID: I've been playing with the cross product definition you gave me. It makes a lot of sense, and I'm sure it will make it a lot easier for me to prove associativity; however, I'm doing something wrong because when I run it, I don't get the result I thought I would. Would you take a look and tell me what I'm doing wrong? def cross(set1,set2): resulting_set = [] for s1 in set1: for s2 in set2: resulting_set.append( (s1, s2) ) return resulting_set set = ['e','a','b', 'ab'] print set s = cross(set,cross(set,set)) print s When I run it, I get the following: ['e', 'a', 'b', 'ab'] [('e', ('e', 'e'))] #Shouldn't I get 64 pairs here instead of one? I thought that a loop would do the trick, but I couldn't figure out how to do it. Can you help? I want to get the entire 64 pairs on my printout. Julieta >From: Daniel Yoo >To: Sheila King >CC: Julieta Rangel , tutor@python.org >Subject: Re: [Tutor] stopping a loop [cross product instead of nested >loops] >Date: Sun, 6 May 2001 02:10:20 -0700 (PDT) > >On Sat, 5 May 2001, Sheila King wrote: > > > On Sat, 05 May 2001 20:24:52 -0500, "Julieta Rangel" > > > wrote about RE: [Tutor] stopping a loop: > > > > :Are you implying a tripple nested loop? meaning > > :for x in set: > > : for y in set: > > : for z in set: > > : if ['x',('y','z')] == [('x','y'),'z']: > > : return associativity holds > > : > > :Is this what you mean? If I give the computer those commands, will it >look > > :for the definition on my dictionary? You see, I'm not sure how I'm >supposed > > :to tell the computer to look in the dictionary for these values and >compare > > :them. Any more hints, ideas, suggestions, comments, questions? > > : > > :Julieta > > > > I'm not sure if Tim was implying a triply-nested loop, or not. It >sounded kind of > > like it to me, too. However, a double-nested loop will do fine. > > > > The key is, you need to use your dictionary to look up the values of the >operations. > > That is the key. That is why you built the dictionary in the first >place. > > >You might find the following definition useful: it's a way of producing >the "cross" product of two lists: > >### >def cross(set1, set2): > resulting_set = [] > for s1 in set1: > for s2 in set2: > resulting_set.append( (s1, s2) ) > return resulting_set >### > > >One reason why the cross product is so useful is because, given any two >lists, it can give back to us all possible pairs of those two lists, all >in a nice list: > >### > >>> cross([1, 2, 3, 4], [1, 2, 3, 4]) >[(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 1), >(3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)] >### > >Or, more evocatively: > >### > >>> numbers = ['1', '2'] > >>> cross(numbers, cross(numbers, numbers)) >[('1', ('1', '1')), ('1', ('1', '2')), ('1', ('2', '1')), > ('1', ('2', '2')), ('2', ('1', '1')), ('2', ('1', '2')), > ('2', ('2', '1')), ('2', ('2', '2'))] >### > >By using the function above, you might not even need any nested loops in >your own code. > > >Hope this helps! > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From julieta_rangel@hotmail.com Mon May 7 02:06:27 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sun, 06 May 2001 20:06:27 -0500 Subject: [Tutor] stopping a loop [cross product instead of nested loops] Message-ID: I've been playing with the cross product definition you gave me. It makes a lot of sense, and I'm sure it will make it a lot easier for me to prove associativity; however, I'm doing something wrong because when I run it, I don't get the result I thought I would. Would you take a look and tell me what I'm doing wrong? def cross(set1,set2): resulting_set = [] for s1 in set1: for s2 in set2: resulting_set.append( (s1, s2) ) return resulting_set set = ['e','a','b', 'ab'] print set s = cross(set,cross(set,set)) print s When I run it, I get the following: ['e', 'a', 'b', 'ab'] [('e', ('e', 'e'))] #Shouldn't I get 64 pairs here instead of one? I thought that a loop would do the trick, but I couldn't figure out how to do it. Can you help? I want to get the entire 64 pairs on my printout. Julieta >From: Daniel Yoo >To: Sheila King >CC: Julieta Rangel , tutor@python.org >Subject: Re: [Tutor] stopping a loop [cross product instead of nested >loops] >Date: Sun, 6 May 2001 02:10:20 -0700 (PDT) > >On Sat, 5 May 2001, Sheila King wrote: > > > On Sat, 05 May 2001 20:24:52 -0500, "Julieta Rangel" > > > wrote about RE: [Tutor] stopping a loop: > > > > :Are you implying a tripple nested loop? meaning > > :for x in set: > > : for y in set: > > : for z in set: > > : if ['x',('y','z')] == [('x','y'),'z']: > > : return associativity holds > > : > > :Is this what you mean? If I give the computer those commands, will it >look > > :for the definition on my dictionary? You see, I'm not sure how I'm >supposed > > :to tell the computer to look in the dictionary for these values and >compare > > :them. Any more hints, ideas, suggestions, comments, questions? > > : > > :Julieta > > > > I'm not sure if Tim was implying a triply-nested loop, or not. It >sounded kind of > > like it to me, too. However, a double-nested loop will do fine. > > > > The key is, you need to use your dictionary to look up the values of the >operations. > > That is the key. That is why you built the dictionary in the first >place. > > >You might find the following definition useful: it's a way of producing >the "cross" product of two lists: > >### >def cross(set1, set2): > resulting_set = [] > for s1 in set1: > for s2 in set2: > resulting_set.append( (s1, s2) ) > return resulting_set >### > > >One reason why the cross product is so useful is because, given any two >lists, it can give back to us all possible pairs of those two lists, all >in a nice list: > >### > >>> cross([1, 2, 3, 4], [1, 2, 3, 4]) >[(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 1), >(3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)] >### > >Or, more evocatively: > >### > >>> numbers = ['1', '2'] > >>> cross(numbers, cross(numbers, numbers)) >[('1', ('1', '1')), ('1', ('1', '2')), ('1', ('2', '1')), > ('1', ('2', '2')), ('2', ('1', '1')), ('2', ('1', '2')), > ('2', ('2', '1')), ('2', ('2', '2'))] >### > >By using the function above, you might not even need any nested loops in >your own code. > > >Hope this helps! > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From julieta_rangel@hotmail.com Mon May 7 03:07:47 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sun, 06 May 2001 21:07:47 -0500 Subject: [Tutor] stopping a loop [cross product instead of nested loops] Message-ID: I've been playing with the cross product definition you gave me. It makes a lot of sense, and I'm sure it will make it a lot easier for me to prove associativity; however, I'm doing something wrong because when I run it, I don't get the result I thought I would. Would you take a look and tell me what I'm doing wrong? def cross(set1,set2): resulting_set = [] for s1 in set1: for s2 in set2: resulting_set.append( (s1, s2) ) return resulting_set set = ['e','a','b', 'ab'] print set s = cross(set,cross(set,set)) print s When I run it, I get the following: ['e', 'a', 'b', 'ab'] [('e', ('e', 'e'))] #Shouldn't I get 64 pairs here instead of one? I thought that a loop would do the trick, but I couldn't figure out how to do it. Can you help? I want to get the entire 64 pairs on my printout. Julieta >From: Daniel Yoo >To: Sheila King >CC: Julieta Rangel , tutor@python.org >Subject: Re: [Tutor] stopping a loop [cross product instead of nested >loops] >Date: Sun, 6 May 2001 02:10:20 -0700 (PDT) > >On Sat, 5 May 2001, Sheila King wrote: > > > On Sat, 05 May 2001 20:24:52 -0500, "Julieta Rangel" > > > wrote about RE: [Tutor] stopping a loop: > > > > :Are you implying a tripple nested loop? meaning > > :for x in set: > > : for y in set: > > : for z in set: > > : if ['x',('y','z')] == [('x','y'),'z']: > > : return associativity holds > > : > > :Is this what you mean? If I give the computer those commands, will it >look > > :for the definition on my dictionary? You see, I'm not sure how I'm >supposed > > :to tell the computer to look in the dictionary for these values and >compare > > :them. Any more hints, ideas, suggestions, comments, questions? > > : > > :Julieta > > > > I'm not sure if Tim was implying a triply-nested loop, or not. It >sounded kind of > > like it to me, too. However, a double-nested loop will do fine. > > > > The key is, you need to use your dictionary to look up the values of the >operations. > > That is the key. That is why you built the dictionary in the first >place. > > >You might find the following definition useful: it's a way of producing >the "cross" product of two lists: > >### >def cross(set1, set2): > resulting_set = [] > for s1 in set1: > for s2 in set2: > resulting_set.append( (s1, s2) ) > return resulting_set >### > > >One reason why the cross product is so useful is because, given any two >lists, it can give back to us all possible pairs of those two lists, all >in a nice list: > >### > >>> cross([1, 2, 3, 4], [1, 2, 3, 4]) >[(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2), (2, 3), (2, 4), (3, 1), >(3, 2), (3, 3), (3, 4), (4, 1), (4, 2), (4, 3), (4, 4)] >### > >Or, more evocatively: > >### > >>> numbers = ['1', '2'] > >>> cross(numbers, cross(numbers, numbers)) >[('1', ('1', '1')), ('1', ('1', '2')), ('1', ('2', '1')), > ('1', ('2', '2')), ('2', ('1', '1')), ('2', ('1', '2')), > ('2', ('2', '1')), ('2', ('2', '2'))] >### > >By using the function above, you might not even need any nested loops in >your own code. > > >Hope this helps! > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From rob@jam.rr.com Mon May 7 03:30:11 2001 From: rob@jam.rr.com (Rob Andrews) Date: Sun, 06 May 2001 21:30:11 -0500 Subject: [Tutor] Re: Possible Useless Python Challenge. References: <3AF4DE75.770921E8@irtc.net> Message-ID: <3AF608B3.BC998B57@jam.rr.com> Thanks for the suggestion. As soon as I can think of the right way to present it, I'll be glad to post it with the other challenges. If anyone has no idea what we're talking about, please forgive. The Useless Challenges are on the Useless Python site, and basically give you the chance to suggest ideas for applications for the general public to decide whether to try and code. Rob Tesla Coil wrote: > > Wondering about this as a possible Useless Python > Challenge. I'd feel a little guilty suggesting it, > as I'm uncertain how difficult a task it is, but > really, Gilbert Roulot is moreso to blame. ;) > > Roulot is the author of the Foks Linux KiSS viewer. > On the homepage, http://perso.wanadoo.fr/issarlk/Foks/ > Roulot lists among "Features and technical stuff" that > Foks is "written in the GNU Sather language. The best > language there is to write KiSS viewers (IMNSHO)!" > > It doesn't appear this has ever been demonstrated > incorrect by a better KiSS viewer being written > in Python--for that matter, any KiSS viewer being > written in Python. > > A KiSS viewer could prove a somewhat larger app than > would be considered "Useless Python," but it probably > qualifies in that one would be writing it perhaps more > to have it done in Python than need for the utility of > Yet Another program with which to play paperdolls... > > KiSS data sets are bundled using LZH compression, > if there's a module for that, I haven't located it. > I suppose that a cel file decoder could be cooked up > using Python Imaging Library, but I've no experience > in that department at all. Other than that, I guess > one is up against reading .cnf files generated by a > variety of editors and sometimes written by hand. > > More introduction & file specs can be found at > http://www2s.biglobe.ne.jp/~yav/kiss/indexe.html -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From dyoo@hkn.eecs.berkeley.edu Mon May 7 03:55:06 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 6 May 2001 19:55:06 -0700 (PDT) Subject: [Tutor] [cross product instead of nested loops] In-Reply-To: Message-ID: On Sun, 6 May 2001, Julieta Rangel wrote: > I've been playing with the cross product definition you gave me. It makes a > lot of sense, and I'm sure it will make it a lot easier for me to prove > associativity; however, I'm doing something wrong because when I run it, I > don't get the result I thought I would. Would you take a look and tell me > what I'm doing wrong? > > > def cross(set1,set2): > resulting_set = [] > for s1 in set1: > for s2 in set2: > resulting_set.append( (s1, s2) ) > return resulting_set ## <-- bug! There's a bug here: we want to return the resulting_set only after we finish going through both for loops. That is: ### def cross(set1,set2): resulting_set = [] for s1 in set1: for s2 in set2: resulting_set.append( (s1, s2) ) return resulting_set ### The difference is in indentation, but the idea is that the request about returning a result should be outside of the looping. After fixing this, the program should work ok. From julieta_rangel@hotmail.com Mon May 7 03:56:35 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sun, 06 May 2001 21:56:35 -0500 Subject: [Tutor] cross product Message-ID: I've been playing with the cross product definition Daniel gave me. It makes a lot of sense, and I'm sure it will make it a lot easier for me to prove associativity; however, I'm doing something wrong because when I run it, I don't get the result I thought I would. Would you take a look and tell me what I'm doing wrong? def cross(set1,set2): resulting_set = [] for s1 in set1: for s2 in set2: resulting_set.append( (s1, s2) ) return resulting_set set = ['e','a','b', 'ab'] print set s = cross(set,cross(set,set)) print s When I run it, I get the following: ['e', 'a', 'b', 'ab'] [('e', ('e', 'e'))] #Shouldn't I get 64 pairs here instead of one? I thought that a loop would do the trick, but I couldn't figure out how to do it. Can you help? I want to get the entire 64 pairs on my printout. Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From julieta_rangel@hotmail.com Mon May 7 04:29:24 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sun, 06 May 2001 22:29:24 -0500 Subject: [Tutor] [cross product instead of nested loops] Message-ID: Thank you. Now it makes sense. By the way, I want to apologize in case you received this message over and over. What happened is that every time I tried to send it I received a message that the e-mail could not be delivered, so I would send it again, and again. Obviously this message could be delivered. I must have been annoying posting the message over and over. Sorry! Julieta >From: Daniel Yoo >To: Julieta Rangel >CC: sheila@thinkspot.net, tutor@python.org >Subject: Re: [Tutor] [cross product instead of nested loops] >Date: Sun, 6 May 2001 19:55:06 -0700 (PDT) > >On Sun, 6 May 2001, Julieta Rangel wrote: > > > I've been playing with the cross product definition you gave me. It >makes a > > lot of sense, and I'm sure it will make it a lot easier for me to prove > > associativity; however, I'm doing something wrong because when I run it, >I > > don't get the result I thought I would. Would you take a look and tell >me > > what I'm doing wrong? > > > > > > def cross(set1,set2): > > resulting_set = [] > > for s1 in set1: > > for s2 in set2: > > resulting_set.append( (s1, s2) ) > > return resulting_set ## <-- bug! > >There's a bug here: we want to return the resulting_set only after we >finish going through both for loops. That is: > >### >def cross(set1,set2): > resulting_set = [] > for s1 in set1: > for s2 in set2: > resulting_set.append( (s1, s2) ) > return resulting_set >### > >The difference is in indentation, but the idea is that the request about >returning a result should be outside of the looping. After fixing this, >the program should work ok. > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From julieta_rangel@hotmail.com Mon May 7 04:40:50 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Sun, 06 May 2001 22:40:50 -0500 Subject: [Tutor] obtaining values from a dictionary Message-ID: I have a list that looks like: c = [('a', ('a', 'a')), ('a', ('a', 'b')), ('a', ('b', 'a')), ('a', ('b', 'b')), ('b', ('a', 'a')), ('b', ('a', 'b')), ('b', ('b', 'a')), ('b', ('b', 'b'))] and I have a dictionary that looks like: d ={('b', 'a'): 'a', ('a', 'a'): 'a', ('a', 'b'): 'b', ('b', 'b'): 'b'} I want to replace the elements in my list according to my dictionary values. In other words, I want to go element by element on my list and ask the computer to give me the corresponding value, according to the dictionary. For example, if I want to get the value of my second element in my list ('a',('a','b')), according to my dictionary, this is equal to ('a','b'), which is equal to b. Can this be done? Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From daniel@longbeach.goldinc.com Mon May 7 05:38:06 2001 From: daniel@longbeach.goldinc.com (Daniel) Date: Sun, 6 May 2001 23:38:06 -0500 (CDT) Subject: [Tutor] obtaining values from a dictionary In-Reply-To: Message-ID: Hello Julieta, I think this is the answer to your question *shrug* :) count = 0 for element in c: if d.has_key(c[count][1]) == 1: print "got it => ", print "dic value is ", d[c[count][1]] c[count] = d[c[count][1]] else: print "nope" count += 1 print "new list is", c -- Daniel, AIM=davignes On Sun, 6 May 2001, Julieta Rangel wrote: > I have a list that looks like: > c = [('a', ('a', 'a')), ('a', ('a', 'b')), ('a', ('b', 'a')), ('a', ('b', > 'b')), ('b', ('a', 'a')), ('b', ('a', 'b')), ('b', ('b', 'a')), ('b', ('b', > 'b'))] > > and I have a dictionary that looks like: > d ={('b', 'a'): 'a', ('a', 'a'): 'a', ('a', 'b'): 'b', ('b', 'b'): 'b'} > > I want to replace the elements in my list according to my dictionary values. > In other words, I want to go element by element on my list and ask the > computer to give me the corresponding value, according to the dictionary. > For example, if I want to get the value of my second element in my list > ('a',('a','b')), according to my dictionary, this is equal to ('a','b'), > which is equal to b. Can this be done? > > Julieta > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From bdupire@seatech.fau.edu Mon May 7 05:39:34 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Mon, 07 May 2001 00:39:34 -0400 Subject: [Tutor] obtaining values from a dictionary References: Message-ID: <3AF62706.7FB6AB3@seatech.fau.edu> This is my try... I did not read all of the previous messages so i don't know very well the context of your question... I assume the question is well formulated. This should do what you want: for i in range(len(c)): # for each element of your list c item1, item2 = c[i] # this element is a tuple --> break it into 2 parts. if d.has_key(item2): # if the 2nd part of the item is in the dictionary d c[i][1]= d[item2] # replace the 2nd part of the tuple with the entry in the dict if d.has_key(c[i]): # now there is a new tuple, so we have to check whether it is or not, once again, in the dictionary c[i] = d[c[i]] # if yes, we replace the tuple with the entry in the dictionary. A common pitfall for this algorithm is to do it like this: for item1, item2 in c: # This does exactly like my first 2 lines. It take an element of c, and breaks it into 2 parts.1 if d.has_key(item2): # if the 2nd part of the item is in the d ictionary d item2= d[item2] # replace the 2nd part of the tuple ------> Trap !!!! this line does not change the list, but the variable item2 See the difference..? i have to do something like c[index] to really change the list.... IOW to refer to it explicitly. Benoit Julieta Rangel wrote: > I have a list that looks like: > c = [('a', ('a', 'a')), ('a', ('a', 'b')), ('a', ('b', 'a')), ('a', ('b', > 'b')), ('b', ('a', 'a')), ('b', ('a', 'b')), ('b', ('b', 'a')), ('b', ('b', > 'b'))] > > and I have a dictionary that looks like: > d ={('b', 'a'): 'a', ('a', 'a'): 'a', ('a', 'b'): 'b', ('b', 'b'): 'b'} > > I want to replace the elements in my list according to my dictionary values. > In other words, I want to go element by element on my list and ask the > computer to give me the corresponding value, according to the dictionary. > For example, if I want to get the value of my second element in my list > ('a',('a','b')), according to my dictionary, this is equal to ('a','b'), > which is equal to b. Can this be done? > > Julieta > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From julieta_rangel@hotmail.com Mon May 7 08:21:01 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Mon, 07 May 2001 02:21:01 -0500 Subject: [Tutor] checking within a table for identity Message-ID: As some of you might remember, I was trying to figure out how to check for associativity within a set. By taking bits and pieces from you all's advice, I put together the following: import string def getCayleyTable(op,set): product = {} for x in set: for y in set: prompt = "%s %s %s = ? "%(x,op,y) print " " z = raw_input(prompt) product [x,y] = z if z not in set: print " " print "No need to go any further: your set is not a group" return product print " " items = product.items() items.sort() return product print " " def cross(set1,set2): resulting_set = [] for s1 in set1: for s2 in set2: resulting_set.append( (s1, s2) ) return resulting_set set = raw_input("Enter the elements of the set separated by a comma,ie, a,b,c: ") set = string.split(set, ",") print " " op = raw_input("Enter the binary operator sign, ie, * : ") d = getCayleyTable( op,set ) print " " m=cross(set,set) v=[] for x in m: v.append(d[x]) print v for x in set: c= cross(set,v) e= cross(v,set) l=[] for x in c: l.append(d[x]) k=[] for x in e: k.append(d[x]) if l!=k: print "your set is not a group" As you can see, I don't have experience in programming, but considering I started learning about a month ago, my program is not that awful. Now I want to figure out how to check for identity on a set. By identity I mean, given a set, there is an element in the set(let's call it e) such that for all elements x, x*e= e*x =x. For example, let's say I have the set {e,a,b,ab}, which is accompanied by the following table: >e*e=e a*e=a b*e=b ab*e=ab >e*a=a a*a=e b*a=ab ab*a=b >e*b=b a*b=ab b*b=e ab*b=a >e*ab=ab a*ab=b b*ab=a ab*ab=e As you might see, the set {e,a,b,ab} has an identity element, which is e. If you check, e*a=a and a*e=a, so e is the identity element of the set. As you can see, you have to do this for every element within the set. What I need to do is to "check whether there is an item in the set, where (item, whatever)== whatever, for each whatever in the set, and also check whether (whatever, item) == whatever." (I'm quoting from one of you guys, I believe it is from Ms. King). Does anyone have any suggestions? Julieta > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From ppathiyi@cisco.com Mon May 7 11:53:13 2001 From: ppathiyi@cisco.com (Praveen Pathiyil) Date: Mon, 7 May 2001 16:23:13 +0530 Subject: [Tutor] Converting a list to a string Message-ID: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc> This is a multi-part message in MIME format. ------=_NextPart_000_012D_01C0D712.038317C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, If i have a list=20 status =3D ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'], is there a single command which will give me a string=20 tftp> Sent 1943 bytes in 0.0 seconds OR do i have to do=20 stat_str =3D '' for elt in status: stat_str =3D stat_str + ' ' + elt TIA, Praveen. ------=_NextPart_000_012D_01C0D712.038317C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi all,
 
If i have a list
status =3D ['tftp>', 'Sent', '1943', = 'bytes',=20 'in', '0.0', 'seconds'],
is there a single command which will = give me a=20 string
tftp> Sent 1943 bytes in 0.0=20 seconds
 
OR do i = have to do=20
 
stat_str =3D ''
for elt in status:
    stat_str=20 =3D stat_str + ' ' + = elt
 
TIA,
Praveen.
------=_NextPart_000_012D_01C0D712.038317C0-- From scarblac@pino.selwerd.nl Mon May 7 11:58:42 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Mon, 7 May 2001 12:58:42 +0200 Subject: [Tutor] Converting a list to a string In-Reply-To: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc>; from ppathiyi@cisco.com on Mon, May 07, 2001 at 04:23:13PM +0530 References: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc> Message-ID: <20010507125842.A31257@pino.selwerd.nl> On 0, Praveen Pathiyil wrote: > Hi all, > > If i have a list > status = ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'], > is there a single command which will give me a string > tftp> Sent 1943 bytes in 0.0 seconds > > OR do i have to do > > stat_str = '' > for elt in status: > stat_str = stat_str + ' ' + elt import string print string.join(status) # If you want something other than a space, # give it as second argument. In new versions you can also spell that " ".join(status) # Join list 'status' with spaces in between -- Remco Gerlich From wheelege@tsn.cc Mon May 7 11:59:15 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Mon, 7 May 2001 20:59:15 +1000 Subject: [Tutor] Converting a list to a string References: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc> Message-ID: <020501c0d6e4$cf904500$0200a8c0@ACE> This is a multi-part message in MIME format. ------=_NextPart_000_0202_01C0D738.935167A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I think you want to have a look at string.join(). For example... >>> import string >>> x =3D ['I', 'am', 'a', 'string'] >>> string.join(x) 'I am a string' You can also specify the separating character as well, with a second = argument. Like... >>> x =3D ['W', 'o', 'r', 'd'] >>> string.join(x, '') 'Word' Hope that helps, Glen. ----- Original Message -----=20 From: Praveen Pathiyil=20 To: tutor@python.org=20 Sent: Monday, May 07, 2001 8:53 PM Subject: [Tutor] Converting a list to a string Hi all, If i have a list=20 status =3D ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'], is there a single command which will give me a string=20 tftp> Sent 1943 bytes in 0.0 seconds OR do i have to do=20 stat_str =3D '' for elt in status: stat_str =3D stat_str + ' ' + elt TIA, Praveen. ------=_NextPart_000_0202_01C0D738.935167A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 
  I think you want to have a look at string.join().
 
  For example...
 
>>> import string
>>> x =3D ['I', 'am', 'a', 'string']
>>>=20 string.join(x)
'I am a string'
 
  You can also specify the separating character as well, with = a second=20 argument.  Like...
 
>>> x =3D ['W', 'o', 'r', 'd']
>>> = string.join(x,=20 '')
'Word'
 
  Hope that helps,
  Glen.
 
----- Original Message -----
From:=20 Praveen=20 Pathiyil
Sent: Monday, May 07, 2001 8:53 = PM
Subject: [Tutor] Converting a = list to a=20 string

Hi all,
 
If i have a list
status =3D ['tftp>', 'Sent', = '1943', 'bytes',=20 'in', '0.0', 'seconds'],
is there a single command which will = give me a=20 string
tftp> Sent 1943 bytes in 0.0=20 seconds
 
OR do i = have to do=20
 
stat_str =3D ''
for elt in status:
    stat_str =3D stat_str + ' ' +=20 elt
 
TIA,
Praveen.
------=_NextPart_000_0202_01C0D738.935167A0-- From ppathiyi@cisco.com Mon May 7 12:10:34 2001 From: ppathiyi@cisco.com (Praveen Pathiyil) Date: Mon, 7 May 2001 16:40:34 +0530 Subject: [Tutor] Converting a list to a string References: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc> <020501c0d6e4$cf904500$0200a8c0@ACE> Message-ID: <016c01c0d6e6$567f0140$37ef87c0@ppathiyipc> This is a multi-part message in MIME format. ------=_NextPart_000_0169_01C0D714.7021E080 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks Glen and Remco. That would definitely serve my purpose. Regards, Praveen. ----- Original Message -----=20 From: Glen Wheeler=20 To: Praveen Pathiyil ; tutor@python.org=20 Sent: Monday, May 07, 2001 4:29 PM Subject: Re: [Tutor] Converting a list to a string I think you want to have a look at string.join(). For example... >>> import string >>> x =3D ['I', 'am', 'a', 'string'] >>> string.join(x) 'I am a string' You can also specify the separating character as well, with a second = argument. Like... >>> x =3D ['W', 'o', 'r', 'd'] >>> string.join(x, '') 'Word' Hope that helps, Glen. ----- Original Message -----=20 From: Praveen Pathiyil=20 To: tutor@python.org=20 Sent: Monday, May 07, 2001 8:53 PM Subject: [Tutor] Converting a list to a string Hi all, =20 If i have a list=20 status =3D ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', = 'seconds'], is there a single command which will give me a string=20 tftp> Sent 1943 bytes in 0.0 seconds OR do i have to do=20 stat_str =3D '' for elt in status: stat_str =3D stat_str + ' ' + elt TIA, Praveen. ------=_NextPart_000_0169_01C0D714.7021E080 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Thanks Glen and Remco.
That would definitely serve my=20 purpose.
 
Regards,
Praveen.
----- Original Message -----
From:=20 Glen = Wheeler
To: Praveen Pathiyil ; tutor@python.org=20
Sent: Monday, May 07, 2001 4:29 = PM
Subject: Re: [Tutor] Converting = a list to=20 a string

 
  I think you want to have a look at string.join().
 
  For example...
 
>>> import string
>>> x =3D ['I', 'am', 'a', 'string']
>>>=20 string.join(x)
'I am a string'
 
  You can also specify the separating character as well, = with a=20 second argument.  Like...
 
>>> x =3D ['W', 'o', 'r', 'd']
>>> = string.join(x,=20 '')
'Word'
 
  Hope that helps,
  Glen.
 
----- Original Message -----
From:=20 Praveen=20 Pathiyil
Sent: Monday, May 07, 2001 = 8:53=20 PM
Subject: [Tutor] Converting a = list to a=20 string

Hi all,
 
If i have a list
status =3D ['tftp>', 'Sent', = '1943', 'bytes',=20 'in', '0.0', 'seconds'],
is there a single command which = will give me a=20 string
tftp> Sent 1943 bytes in 0.0=20 seconds
 
OR do i = have to do=20
 
stat_str =3D ''
for elt in status:
    stat_str =3D stat_str + ' ' +=20 elt
 
TIA,
Praveen.
------=_NextPart_000_0169_01C0D714.7021E080-- From arcege@speakeasy.net Mon May 7 12:15:41 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Mon, 7 May 2001 07:15:41 -0400 (EDT) Subject: [Tutor] Converting a list to a string In-Reply-To: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc> from "Praveen Pathiyil" at May 07, 2001 04:23:13 PM Message-ID: <200105071115.f47BFfS01582@dsl092-074-184.bos1.dsl.speakeasy.net> Praveen Pathiyil wrote > Hi all, > > If i have a list=20 > status =3D ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'], > is there a single command which will give me a string=20 > tftp> Sent 1943 bytes in 0.0 seconds > > OR do i have to do=20 > > stat_str =3D '' > for elt in status: > stat_str =3D stat_str + ' ' + elt You don't _have_ to do that; in fact, concatenating strings that way is very inefficient (the left hand of the '+' is copied each time through the loop). There is a join function/method for strings to do this for you. In Python 2.0 and higher, you can use string methods, but on the joiner (in this case the space): stat_str = ' '.join(status) In earlier releases, use the join function in the string module: import string stat_str = string.join(status) Also, if you use the loop above, you'll have an extra space in the front of the resulting string. You won't get that with the join routines. -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From sheila@thinkspot.net Mon May 7 14:04:46 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 07 May 2001 06:04:46 -0700 Subject: [Tutor] checking within a table for identity In-Reply-To: References: Message-ID: <28386736E4B@kserver.org> On Mon, 07 May 2001 02:21:01 -0500, "Julieta Rangel" wrote about [Tutor] checking within a table for identity: : :As you might see, the set {e,a,b,ab} has an identity element, which is e. If :you check, e*a=a and a*e=a, so e is the identity element of the set. As you :can see, you have to do this for every element within the set. What I need :to do is to "check whether there is an item in the set, where (item, :whatever)== whatever, for each whatever in the set, and also check whether :(whatever, item) == whatever." (I'm quoting from one of you guys, I believe :it is from Ms. King). Does anyone have any suggestions? I would probably write a function IsIdentityElement(elt, set) Where the function would take the element, and check for each item in the set if (elt, item) == item and (item, elt) == item This would require a loop. (Sometime like for item in set: ) I would have IsIdentity Element return a 1 if the elt turned out to be the Identity Element, and have it return 0, otherwise. Probably I'd have it test for not (elt, item) == item and not (item, elt) == item And if it came out to be the case, that it was not the identity element, return 0 immediately (which would make it break out of the loop. If I made it through all the loops without breaking out and returning a zero, have it return 1, because it passed all the tests and must be the identity element. When you call it in your script's main body, you need a loop there, too, to check for all the items in the set, whether any one of them might be the identity element. for elt in set: if IsIdentityElement(elt, set): print "found the identity element. It is ", elt break Well, maybe that will give you a starting idea? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From NHYTRO@compuserve.com Mon May 7 14:38:21 2001 From: NHYTRO@compuserve.com (Sharriff Aina) Date: Mon, 7 May 2001 09:38:21 -0400 Subject: [Tutor] Python CGI-HTML editor Message-ID: <200105070938_MC2-D005-A842@compuserve.com> Hi List! I have coded an HTML online editor with the help of several Python CGI scripts. I=B4m now faced woth the problem of image insertion, I know how = to upload files per CGI-Python to a server, but I still have 1 complicated hurdle: 1. Is it possilbe to start a file upload AND send text data from a HTML form at the same time? I know this question is not 100% python related, I was=B4nt sure where I should start looking for information. Does one have a URL for me where HT= ML based online text editors are described? Best regards Sharriff P.S thanks to all that have helped me in the last few weeks. = From dyoo@hkn.eecs.berkeley.edu Mon May 7 16:33:16 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 7 May 2001 08:33:16 -0700 (PDT) Subject: [Tutor] Converting a list to a string In-Reply-To: <013001c0d6e3$ea66cda0$37ef87c0@ppathiyipc> Message-ID: On Mon, 7 May 2001, Praveen Pathiyil wrote: > If i have a list > status = ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'], > is there a single command which will give me a string > tftp> Sent 1943 bytes in 0.0 seconds > > OR do i have to do > > stat_str = '' > for elt in status: > stat_str = stat_str + ' ' + elt People have suggested using string.join(), which is how I'd approach this problem. However, if you already know how many elements are in your status list, you can also use string interpolation toward the cause. stat_str = "%s %s %s %s %s %s %s %s" % tuple(status) would work, assuming that status is an 8-element list. Good luck! From pdiaz88@terra.es Mon May 7 19:18:08 2001 From: pdiaz88@terra.es (Pedro Diaz Jimenez) Date: Mon, 7 May 2001 18:18:08 +0000 Subject: [Tutor] Converting a list to a string In-Reply-To: <200105071115.f47BFfS01582@dsl092-074-184.bos1.dsl.speakeasy.net> References: <200105071115.f47BFfS01582@dsl092-074-184.bos1.dsl.speakeasy.net> Message-ID: <01050718180800.01701@duero> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Monday 07 May 2001 11:15, Michael P. Reilly wrote: > Praveen Pathiyil wrote > > > Hi all, > > > > If i have a list=20 > > status =3D ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'], > > is there a single command which will give me a string=20 > > tftp> Sent 1943 bytes in 0.0 seconds > > > > OR do i have to do=20 > > > > stat_str =3D '' > > for elt in status: > > stat_str =3D stat_str + ' ' + elt > > You don't _have_ to do that; in fact, concatenating strings that way is > very inefficient (the left hand of the '+' is copied each time through the > loop). There is a join function/method for strings to do this for you. > > In Python 2.0 and higher, you can use string methods, but on the joiner > (in this case the space): > stat_str = ' '.join(status) > > In earlier releases, use the join function in the string module: > import string > stat_str = string.join(status) > > Also, if you use the loop above, you'll have an extra space in the > front of the resulting string. You won't get that with the join > routines. > > -Arcege Python 1.5.2 (#0, Dec 27 2000, 13:59:38) [GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> A=['a','b','c','d','e'] >>> reduce( lambda x,y:x+y, A ) 'abcde' >>> reduce( lambda x,y:x+" "+y,A ... ) 'a b c d e' >>> Just my 0.02 Cheers Pedro - -- /* * Pedro Diaz Jimenez * pdiaz88@terra.es * pdiaz@acm.asoc.fi.upm.es * * Wanna see how 100000! looks like?: * http://acm.asoc.fi.upm.es/~pdiaz/fact_100.000 * * La sabiduria me persigue, pero yo soy mas rapido */ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE69ubhnu53feEYxlERAswoAKDYUvpGFAUcBr/bOdpiw+YO2/K6xgCeKYaH BatcOi4FoBG1LWai9BRh7bs= =zt1L -----END PGP SIGNATURE----- From sheila@thinkspot.net Mon May 7 17:45:16 2001 From: sheila@thinkspot.net (Sheila King) Date: Mon, 7 May 2001 09:45:16 -0700 Subject: [Tutor] checking within a table for identity Message-ID: Previously, I suggested using code something like this: I would probably write a function IsIdentityElement(elt, set) Later I thought, you probably need to pass the table/dictionary you made, as well, because you will need it to find the value of things like (elt, identity) You need to look those values up in the table. So probably you need to start the function off like this: IsIdentityElement(elt, set, table) My other remarks are just a hint at how you might do the problem. I typed it off really quickly this morning, before leaving for work. It is incomplete. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From stevej@parlant.com Mon May 7 17:47:37 2001 From: stevej@parlant.com (Steve Jibson) Date: Mon, 07 May 2001 10:47:37 -0600 Subject: [Tutor] Tkinter app and the windows system tray Message-ID: <3AF6D1A9.F80D4D27@parlant.com> I have writtne a small tkinter app (for windows) and I want it to run on system startup and put a little icon in the windows system tray (you know, like off of those other lame programs with icons on the right side of the start bar). Anyway, I'm not sure where to even look for info on how to interact with the system tray. Can someone give me some info or point me to some? Thanks, Steve Jibson steve@jibson.com From arcege@speakeasy.net Mon May 7 18:58:48 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Mon, 7 May 2001 13:58:48 -0400 (EDT) Subject: [Tutor] Converting a list to a string In-Reply-To: from "Daniel Yoo" at May 07, 2001 08:33:16 AM Message-ID: <200105071758.f47HwmG02006@dsl092-074-184.bos1.dsl.speakeasy.net> Daniel Yoo wrote > > On Mon, 7 May 2001, Praveen Pathiyil wrote: > > > If i have a list > > status = ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'], > > is there a single command which will give me a string > > tftp> Sent 1943 bytes in 0.0 seconds > > > > OR do i have to do > > > > stat_str = '' > > for elt in status: > > stat_str = stat_str + ' ' + elt > > People have suggested using string.join(), which is how I'd approach this > problem. > > However, if you already know how many elements are in your status list, > you can also use string interpolation toward the cause. > > stat_str = "%s %s %s %s %s %s %s %s" % tuple(status) > > would work, assuming that status is an 8-element list. Likewise, if you don't know how many: >>> if status: # there's at least one ... spam_str = '%s' + ' %s' * (len(status)-1) ... stat_str = spam_str % tuple(status) ... else: ... stat_str = '' ... But I think join is faster than this. ;) -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From julieta_rangel@hotmail.com Mon May 7 20:29:39 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Mon, 07 May 2001 14:29:39 -0500 Subject: [Tutor] checking within a table for identity Message-ID: As you might recall, I'm trying to figure out a way to check whether a set is a group or not (group: closed, associative, identity, inverse). I have the closure and associativity parts. Now I'm checking for an identity element within a set. The following is what I have so far: import string def getCayleyTable(op,set): product = {} for x in set: for y in set: prompt = "%s %s %s = ? "%(x,op,y) print " " z = raw_input(prompt) product [x,y] = z if z not in set: print " " print "No need to go any further: your set is not a group. " print "Your set is not closed under \" %s \"" %op return product break print " " items = product.items() items.sort() return product print " " def cross(set1,set2): resulting_set = [] for s1 in set1: for s2 in set2: resulting_set.append( (s1, s2) ) return resulting_set def IsIdentityElement(x, set,d): unsuccess=0 for x in set: if d[(x, y)]==x and d[(y,x)]==x: return y if not d[(x,y)]==x and not d[(y,x)]==x: unsuccess=1 break if unsuccess ==1: print "there is no identity element for your set" break set = raw_input("Enter the elements of the set separated by a comma,ie, a,b,c: ") set = string.split(set, ",") print " " op = raw_input("Enter the binary operator sign, ie, * : ") d = getCayleyTable( op,set ) print " " print d m=cross(set,set) print m n=[] for x in m: n.append(d[x]) print n for x in set: c= cross(set,n) e= cross(n,set) print c print e l=[] for x in c: l.append(d[x]) print l k=[] for x in e: k.append(d[x]) print k if l!=k: print "your set is not a group, associativity fails" else: print "closure and associativity hold" for elt in set: if IsIdentityElement(x, set,d): print "the identity element is " ,y break I'm doing something wrong, but I can't figure out what it is. If I run the program with a set that has an identity, it runs, but does not display any messages. I want it to tell me what the identity element is, but I don't know how to tell the computer to do this. If I run the program with a set in which closure and associativity hold, but there is no identity element, I get an error message. Again, I would like the computer to display a message telling me that the set has no identity, therefore it is not a group, but again, I don't know how. Can you help me? If you know what I'm doing wrong and have any suggestions. By the way, the following is what I get when the set has an identity: Enter the elements of the set separated by a comma,ie, a,b,c: e,a,b,ab Enter the binary operator sign, ie, * : * e * e = ? e e * a = ? a e * b = ? b e * ab = ? ab a * e = ? a a * a = ? e a * b = ? ab a * ab = ? b b * e = ? b b * a = ? ab b * b = ? e b * ab = ? a ab * e = ? ab ab * a = ? b ab * b = ? a ab * ab = ? e {('a', 'e'): 'a', ('ab', 'e'): 'ab', ('a', 'a'): 'e', ('a', 'ab'): 'b', ('b', 'ab'): 'a', ('a', 'b'): 'ab', ('ab', 'ab'): 'e', ('ab', 'a'): 'b', ('b', 'e'): 'b', ('e', 'a'): 'a', ('e', 'b'): 'b', ('e', 'ab'): 'ab', ('b', 'a'): 'ab', ('e', 'e'): 'e', ('ab', 'b'): 'a', ('b', 'b'): 'e'} [('e', 'e'), ('e', 'a'), ('e', 'b'), ('e', 'ab'), ('a', 'e'), ('a', 'a'), ('a', 'b'), ('a', 'ab'), ('b', 'e'), ('b', 'a'), ('b', 'b'), ('b', 'ab'), ('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab')] ['e', 'a', 'b', 'ab', 'a', 'e', 'ab', 'b', 'b', 'ab', 'e', 'a', 'ab', 'b', 'a', 'e'] [('e', 'e'), ('e', 'a'), ('e', 'b'), ('e', 'ab'), ('e', 'a'), ('e', 'e'), ('e', 'ab'), ('e', 'b'), ('e', 'b'), ('e', 'ab'), ('e', 'e'), ('e', 'a'), ('e', 'ab'), ('e', 'b'), ('e', 'a'), ('e', 'e'), ('a', 'e'), ('a', 'a'), ('a', 'b'), ('a', 'ab'), ('a', 'a'), ('a', 'e'), ('a', 'ab'), ('a', 'b'), ('a', 'b'), ('a', 'ab'), ('a', 'e'), ('a', 'a'), ('a', 'ab'), ('a', 'b'), ('a', 'a'), ('a', 'e'), ('b', 'e'), ('b', 'a'), ('b', 'b'), ('b', 'ab'), ('b', 'a'), ('b', 'e'), ('b', 'ab'), ('b', 'b'), ('b', 'b'), ('b', 'ab'), ('b', 'e'), ('b', 'a'), ('b', 'ab'), ('b', 'b'), ('b', 'a'), ('b', 'e'), ('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab'), ('ab', 'a'), ('ab', 'e'), ('ab', 'ab'), ('ab', 'b'), ('ab', 'b'), ('ab', 'ab'), ('ab', 'e'), ('ab', 'a'), ('ab', 'ab'), ('ab', 'b'), ('ab', 'a'), ('ab', 'e')] [('e', 'e'), ('e', 'a'), ('e', 'b'), ('e', 'ab'), ('a', 'e'), ('a', 'a'), ('a', 'b'), ('a', 'ab'), ('b', 'e'), ('b', 'a'), ('b', 'b'), ('b', 'ab'), ('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab'), ('a', 'e'), ('a', 'a'), ('a', 'b'), ('a', 'ab'), ('e', 'e'), ('e', 'a'), ('e', 'b'), ('e', 'ab'), ('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab'), ('b', 'e'), ('b', 'a'), ('b', 'b'), ('b', 'ab'), ('b', 'e'), ('b', 'a'), ('b', 'b'), ('b', 'ab'), ('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab'), ('e', 'e'), ('e', 'a'), ('e', 'b'), ('e', 'ab'), ('a', 'e'), ('a', 'a'), ('a', 'b'), ('a', 'ab'), ('ab', 'e'), ('ab', 'a'), ('ab', 'b'), ('ab', 'ab'), ('b', 'e'), ('b', 'a'), ('b', 'b'), ('b', 'ab'), ('a', 'e'), ('a', 'a'), ('a', 'b'), ('a', 'ab'), ('e', 'e'), ('e', 'a'), ('e', 'b'), ('e', 'ab')] ['e', 'a', 'b', 'ab', 'a', 'e', 'ab', 'b', 'b', 'ab', 'e', 'a', 'ab', 'b', 'a', 'e', 'a', 'e', 'ab', 'b', 'e', 'a', 'b', 'ab', 'ab', 'b', 'a', 'e', 'b', 'ab', 'e', 'a', 'b', 'ab', 'e', 'a', 'ab', 'b', 'a', 'e', 'e', 'a', 'b', 'ab', 'a', 'e', 'ab', 'b', 'ab', 'b', 'a', 'e', 'b', 'ab', 'e', 'a', 'a', 'e', 'ab', 'b', 'e', 'a', 'b', 'ab'] ['e', 'a', 'b', 'ab', 'a', 'e', 'ab', 'b', 'b', 'ab', 'e', 'a', 'ab', 'b', 'a', 'e', 'a', 'e', 'ab', 'b', 'e', 'a', 'b', 'ab', 'ab', 'b', 'a', 'e', 'b', 'ab', 'e', 'a', 'b', 'ab', 'e', 'a', 'ab', 'b', 'a', 'e', 'e', 'a', 'b', 'ab', 'a', 'e', 'ab', 'b', 'ab', 'b', 'a', 'e', 'b', 'ab', 'e', 'a', 'a', 'e', 'ab', 'b', 'e', 'a', 'b', 'ab'] closure and associativity hold And the following is what I get if the set has no identity: Enter the elements of the set separated by a comma,ie, a,b,c: 0,2,4 Enter the binary operator sign, ie, * : * 0 * 0 = ? 0 0 * 2 = ? 0 0 * 4 = ? 0 2 * 0 = ? 0 2 * 2 = ? 4 2 * 4 = ? 0 4 * 0 = ? 0 4 * 2 = ? 0 4 * 4 = ? 0 {('4', '2'): '0', ('0', '4'): '0', ('0', '2'): '0', ('0', '0'): '0', ('2', '4'): '0', ('4', '4'): '0', ('4', '0'): '0', ('2', '0'): '0', ('2', '2'): '4'} [('0', '0'), ('0', '2'), ('0', '4'), ('2', '0'), ('2', '2'), ('2', '4'), ('4', '0'), ('4', '2'), ('4', '4')] ['0', '0', '0', '0', '4', '0', '0', '0', '0'] [('0', '0'), ('0', '0'), ('0', '0'), ('0', '0'), ('0', '4'), ('0', '0'), ('0', '0'), ('0', '0'), ('0', '0'), ('2', '0'), ('2', '0'), ('2', '0'), ('2', '0'), ('2', '4'), ('2', '0'), ('2', '0'), ('2', '0'), ('2', '0'), ('4', '0'), ('4', '0'), ('4', '0'), ('4', '0'), ('4', '4'), ('4', '0'), ('4', '0'), ('4', '0'), ('4', '0')] [('0', '0'), ('0', '2'), ('0', '4'), ('0', '0'), ('0', '2'), ('0', '4'), ('0', '0'), ('0', '2'), ('0', '4'), ('0', '0'), ('0', '2'), ('0', '4'), ('4', '0'), ('4', '2'), ('4', '4'), ('0', '0'), ('0', '2'), ('0', '4'), ('0', '0'), ('0', '2'), ('0', '4'), ('0', '0'), ('0', '2'), ('0', '4'), ('0', '0'), ('0', '2'), ('0', '4')] ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'] ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'] Traceback (innermost last): File "", line 1, in ? reload(seta) File "C:\Program Files\Python\seta.py", line 76, in ? if IsIdentityElement(elt, set,d): File "C:\Program Files\Python\seta.py", line 35, in IsIdentityElement if d[(x, y)]==x and d[(y,x)]==x: KeyError: ('0', 'b') The lists I have displayed every time I run the program are just for me to figure out what is going on. I'll get rid of them when the program is complete. >From: Sheila King >Reply-To: sheila@thinkspot.net >To: tutor@python.org >CC: julieta_rangel@hotmail.com >Subject: Re: [Tutor] checking within a table for identity >Date: Mon, 7 May 2001 09:45:16 -0700 > >Previously, I suggested using code something like this: > >I would probably write a function > >IsIdentityElement(elt, set) > >Later I thought, you probably need to pass the table/dictionary you >made, as well, because you will need it to find the value of things >like >(elt, identity) > >You need to look those values up in the table. > >So probably you need to start the function off like this: > >IsIdentityElement(elt, set, table) > >My other remarks are just a hint at how you might do the problem. >I typed it off really quickly this morning, before leaving for work. >It is incomplete. > > >-- >Sheila King >http://www.thinkspot.net/sheila/ >http://www.k12groups.org/ > > > > > > > > > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From glingl@aon.at Mon May 7 22:34:44 2001 From: glingl@aon.at (Gregor Lingl) Date: Mon, 07 May 2001 23:34:44 +0200 Subject: [Tutor] Converting a list to a string References: Message-ID: <3AF714F4.C421E2A4@aon.at> Daniel Yoo schrieb: > On Mon, 7 May 2001, Praveen Pathiyil wrote: > > > If i have a list > > status = ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'], > > is there a single command which will give me a string > > tftp> Sent 1943 bytes in 0.0 seconds > > > > OR do i have to do > > > > stat_str = '' > > for elt in status: > > stat_str = stat_str + ' ' + elt > > People have suggested using string.join(), which is how I'd approach this > problem. > > However, if you already know how many elements are in your status list, > you can also use string interpolation toward the cause. > > stat_str = "%s %s %s %s %s %s %s %s" % tuple(status) > > would work, assuming that status is an 8-element list. ... or if you don't know the lenght of the list, you may use: stat_str = len(status) * "%s " % tuple(status) which however is definitly neither nicer nor more compact than stat_str = " ".join(status) which is possible since (Python 1.6) Gregor L. From jenca@email.com Tue May 8 02:06:31 2001 From: jenca@email.com (Jenkins) Date: Mon, 7 May 2001 18:06:31 -0700 Subject: [Tutor] What i should do? Message-ID: <000801c0d75b$20534de0$0100000a@server> This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C0D720.72B713E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable After I write the code for my program how can I make it to work, how can = I create the program ------=_NextPart_000_0005_01C0D720.72B713E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
After I write the code for my program = how can I=20 make it to work, how can I create the program
------=_NextPart_000_0005_01C0D720.72B713E0-- From bdupire@seatech.fau.edu Mon May 7 23:15:25 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Mon, 07 May 2001 18:15:25 -0400 Subject: [Tutor] What i should do? References: <000801c0d75b$20534de0$0100000a@server> Message-ID: <3AF71E7D.2C624A6D@seatech.fau.edu> You need to create a new file in your editor, to put the code in it and save it as a file with a .py extension, like "my_program.py" You've just created a new python module. If you're running Windows, click on the Python icon, to start the Python interpreter and you can then import your module, just typing: import my_program You can learn about this at: http://www.python.org/doc/current/tut/node8.html The Python tutorial is at: http://www.python.org/doc/current/tut/tut.html Benoit Jenkins wrote: > After I write the code for my program how can I make it to work, how > can I create the program -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From julieta_rangel@hotmail.com Mon May 7 23:18:05 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Mon, 07 May 2001 17:18:05 -0500 Subject: [Tutor] checking if all items in a list are the same Message-ID: If I have a list, how can I compare all of the elements to check if they are the same? Say that I have the following list: [e,e,e,e,e] How can I tell the computer to go item by item in the list and compare them. If they are the same, I want the computer to tell me that it has found the identity element, and if they are not the same, I want the computer to tell me that there is no identity element. Can anyone help? Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From shaleh@valinux.com Mon May 7 23:30:50 2001 From: shaleh@valinux.com (Sean 'Shaleh' Perry) Date: Mon, 07 May 2001 15:30:50 -0700 (PDT) Subject: [Tutor] checking if all items in a list are the same In-Reply-To: Message-ID: On 07-May-2001 Julieta Rangel wrote: > If I have a list, how can I compare all of the elements to check if they are > the same? Say that I have the following list: > > [e,e,e,e,e] > > How can I tell the computer to go item by item in the list and compare them. > If they are the same, I want the computer to tell me that it has found the > identity element, and if they are not the same, I want the computer to tell > me that there is no identity element. Can anyone help? > Often times it helps to consider the problem as a person would the very first time. "How do I tell if a bunch of things are the same?" Hmm, I would take an item and then look at another item and decide if they are the same. Then while still holding that first item in mind, I would look at all of the items. Along the way I might notice that some items are like others but not the first item I chose. Sure, this may not be the best way, but it is always more important to get something working, then make it work at maxmimum efficiency. From deirdre@deirdre.net Mon May 7 23:27:28 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Mon, 7 May 2001 15:27:28 -0700 Subject: [Tutor] checking if all items in a list are the same In-Reply-To: References: Message-ID: >If I have a list, how can I compare all of the elements to check if >they are the same? Say that I have the following list: > >[e,e,e,e,e] > >How can I tell the computer to go item by item in the list and >compare them. If they are the same, I want the computer to tell me >that it has found the identity element, and if they are not the >same, I want the computer to tell me that there is no identity >element. Can anyone help? If you return a -1 from a function when there's no match, or a zero when there's a match. This assumes ALL items in the list are identical to the match item: def listMatch(aList, itemToMatch) for i in aList: if i != itemToMatch: return -1 return 0 -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From babyboy@oninet.pt Tue May 8 00:08:23 2001 From: babyboy@oninet.pt (wilson edgar) Date: Tue, 8 May 2001 00:08:23 +0100 Subject: [Tutor] What i should do? References: <000801c0d75b$20534de0$0100000a@server> Message-ID: <001a01c0d74a$9e4d6d40$1a083ad5@a7u4r2> Esta é uma mensagem com várias partes em formato MIME. ------=_NextPart_000_0017_01C0D752.FF519280 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable well, if you have the system varibles set correctly, you just have to go = to you prompt and type: ex: c:\>python nameOfTheProgram.py This means that after writting the code you have to save in a .py and = the execute it. here you have some very good starting points =20 http://www.python.org/doc/current/tut/tut.html http://www.crosswinds.net/~agauld/ hth wilson edgar After I write the code for my program how can I make it to work, how = can I create the program ------=_NextPart_000_0017_01C0D752.FF519280 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
well, if you have the system varibles = set=20 correctly, you just have to go to you prompt and type:
 
ex:
c:\>python = nameOfTheProgram.py
 
This means that after writting the code = you have to=20 save in a .py and the execute it.
here you have some very good starting=20 points
 
http://www.python= .org/doc/current/tut/tut.html
 
http://www.crosswinds.net/~ag= auld/
 
hth
wilson edgar
 
After I write the code for my program = how can I=20 make it to work, how can I create the=20 program
------=_NextPart_000_0017_01C0D752.FF519280-- From kstoner@netins.net Tue May 8 00:12:50 2001 From: kstoner@netins.net (Katharine Stoner) Date: Mon, 7 May 2001 18:12:50 -0500 Subject: [Tutor] meaning Message-ID: <000e01c0d74b$3d261980$7752b1cf@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_000B_01C0D721.53C0A2C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, Would someone be so kind as to explain what this bit of code means line = by line. Mostly I would like to know what the first four lines mean. Thanks, -Cameron #!/usr/local/bin/python def spam(n, l =3D[] ) : l.append(n) return l x =3D spam(42) print x y =3D spam(39) print y z =3D spam(9999, y) print x, y, z ------=_NextPart_000_000B_01C0D721.53C0A2C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi all,
 
Would someone be so kind as to explain = what this=20 bit of code means line by line.
Mostly I would like to know what the = first four=20 lines mean.
Thanks,
-Cameron
 
#!/usr/local/bin/python
def spam(n, l =3D[] ) :
    = l.append(n)
    return = l
 
x =3D spam(42)
print x
y =3D spam(39)
print y
z =3D spam(9999, y)
print x, y, = z
------=_NextPart_000_000B_01C0D721.53C0A2C0-- From scarblac@pino.selwerd.nl Tue May 8 00:22:44 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 8 May 2001 01:22:44 +0200 Subject: [Tutor] meaning In-Reply-To: <000e01c0d74b$3d261980$7752b1cf@oemcomputer>; from kstoner@netins.net on Mon, May 07, 2001 at 06:12:50PM -0500 References: <000e01c0d74b$3d261980$7752b1cf@oemcomputer> Message-ID: <20010508012244.A20127@pino.selwerd.nl> On 0, Katharine Stoner wrote: > Hi all, > > Would someone be so kind as to explain what this bit of code means line by line. > Mostly I would like to know what the first four lines mean. > Thanks, > -Cameron > > #!/usr/local/bin/python This line tells the system that it's a Python file (on Unix/Linux). > def spam(n, l =[] ) : > l.append(n) > return l This creates a function called spam. It takes two arguments, n and l. The second is optional. If it isn't given, l is set to a list that is initially []. It will be the same list object every time the function is called. Then, n is appended to the list l, and l is returned as the result of the function. > x = spam(42) Spam is called with n=42 and no l. So l is the list [], 42 is appended, so [42] is returned, and x now refers to the list. > print x So this prints [42]. > y = spam(39) Same story, n=39, l was [42] (remember, it's the same list all the time!) and becomes [42, 39]. > print y Prints [42, 39]. > z = spam(9999, y) Now n=9999, and l=y. Since y was the result of the previous call, and it's still that same list as always, l=[42, 39] and becomes [42, 39, 9999]. > print x, y, z They're all the same list, the one that was made when the def: statement was run. So this prints [42, 39, 9999] [42, 39, 9999] [42, 39, 9999] -- Remco Gerlich From bdupire@seatech.fau.edu Tue May 8 00:29:09 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Mon, 07 May 2001 19:29:09 -0400 Subject: [Tutor] meaning References: <000e01c0d74b$3d261980$7752b1cf@oemcomputer> Message-ID: <3AF72FC4.EA59E85F@seatech.fau.edu> This piece of code illustrates the fact that default arguments in a function are only evaluated once. I ve just seen Remco answered your question... so read his message ! :o) Benoit Katharine Stoner wrote: > Hi all, Would someone be so kind as to explain what this bit of code > means line by line.Mostly I would like to know what the first four > lines mean.Thanks,-Cameron #!/usr/local/bin/pythondef spam(n, l =[] ) > : l.append(n) return l x = spam(42)print xy = spam(39)print yz = > spam(9999, y)print x, y, z -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From bsass@freenet.edmonton.ab.ca Tue May 8 00:58:06 2001 From: bsass@freenet.edmonton.ab.ca (Bruce Sass) Date: Mon, 7 May 2001 17:58:06 -0600 (MDT) Subject: [Tutor] meaning In-Reply-To: <000e01c0d74b$3d261980$7752b1cf@oemcomputer> Message-ID: On Mon, 7 May 2001, Cameron wrote: > Hi all, > > Would someone be so kind as to explain what this bit of code means line by line. > Mostly I would like to know what the first four lines mean. > Thanks, > -Cameron > > #!/usr/local/bin/python Tells the shell to hand the file off to the python interpreter at /usr/local/bin/python, probably a hardlink to python1.5|2.0|2.1 > def spam(n, l =[] ) : Defines a function named "spam" with two parameters, one is required the other defaults to being an empty list the first time the function is used. This is what you usually want... def spam(n, l = None): if l == None: l = [] This way you create a new list object each time you don't pass a second argument, instead of creating one only when the function gets compiled. > l.append(n) appends n to l; n can be anything, l can be anything with an "append" method > return l returns the object "l" as the result > x = spam(42) > print x > y = spam(39) > print y > z = spam(9999, y) > print x, y, z print id(x), id(y), id(z) - Bruce From dyoo@hkn.eecs.berkeley.edu Tue May 8 01:53:41 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 7 May 2001 17:53:41 -0700 (PDT) Subject: [Tutor] Tkinter app and the windows system tray In-Reply-To: <3AF6D1A9.F80D4D27@parlant.com> Message-ID: On Mon, 7 May 2001, Steve Jibson wrote: > > I have writtne a small tkinter app (for windows) and I want it to run on > system startup and put a little icon in the windows system tray (you > know, like off of those other lame programs with icons on the right side > of the start bar). Anyway, I'm not sure where to even look for info on You might find the following program useful for putting stuff in your system tray: http://www.davecentral.com/13293.html It's called Watchcat, and it lets you put any programs on the system tray. You might also want to ask people on comp.lang.python: people there might have experience with doing Windowish stuff there. > how to interact with the system tray. Can someone give me some info or > point me to some? It sounds like you might also be interested in py2exe, which will help package your Tkinter program so that you'll be able to share it with your friends: http://py2exe.sourceforge.net Good luck to you! From dyoo@hkn.eecs.berkeley.edu Tue May 8 02:39:24 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 7 May 2001 18:39:24 -0700 (PDT) Subject: [Tutor] Most efficient representation of a tree? [a list representation] In-Reply-To: <3AF3451D.BCBAF3F3@verio.net> Message-ID: On Fri, 4 May 2001, VanL wrote: > What would be the most efficient representation of a tree? > In this tree, each node could have an arbitrary number of children. > I also wanted to be able to order the children so I can traverse the > trees in different ways (preorder, postorder, etc). Anyway, at least a > leftmost-child, right-sibling ordering. > > I was considering two options: > > 1. A modification of Guido's adjacency-list implementation of a graph > (see http://www.python.org/doc/essays/graphs.html). After all, this > sort of tree is just special case sparse graph. > > 2. A node class with a parent link and a list of links to each child -- > essentially a generalization of the linked list class that I posted here > a month ago. > > Any other options? Apologies for the late reply! I'm choosing option two: it's fairly easy to work with. I can put up sample code that implements this as soon as I get home. There's another way to do this, of course. There's a representation of binary trees that uses flat lists, and this is one is especially cute: ### def left(index): return 2 * index + 1 def right(index): return 2 * index + 2 def parent(index): return index / 2 def inorder(tree, index): """Here's a sample algorithm that uses this tree representation. Inorder traversal.""" if index >= len(tree): return inorder(tree, left(index)) print tree[index] inorder(tree, right(index)) def preorder(tree, index): if index >= len(tree): return print tree[index] preorder(tree, left(index)) preorder(tree, right(index)) if __name__ == '__main__': mytree = [1, 2, 3, 4, 5, 6, 7, 8] print "Here's an inorder traversal of our mytree." inorder(mytree, 0) ## Start an inorder traversal at the root at 0. print print "Here's a preorder traversal:" preorder(mytree, 0) ### The idea is to store our data in a list, and to jump around in our tree by index number. Getting at our left or right child is simple: we just do a little arithmetic on our current position. What's particularly interesting is that this representation allows us to grab the parent of the node really easily. All of this is done without explicitily storing left/right references: it's all done with indices, so it also saves some space, if you're into space efficiency. Binary trees can represent general trees, so this should be enough to make a good general tree. Hope this helps! From dyoo@hkn.eecs.berkeley.edu Tue May 8 02:42:44 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 7 May 2001 18:42:44 -0700 (PDT) Subject: [Tutor] Possible Useless Python Challenge. In-Reply-To: <3AF4DE75.770921E8@irtc.net> Message-ID: On Sun, 6 May 2001, Tesla Coil wrote: > KiSS data sets are bundled using LZH compression, > if there's a module for that, I haven't located it. I haven't found an LZH decompressor for Python. In fact, the GnomeKISS people are depending on a separate LHA extraction program, so perhaps a Python KISS program should delegate the handling of LZH compression to the LHA utility. > I suppose that a cel file decoder could be cooked up using Python > Imaging Library, but I've no experience in that department at all. > Other than that, I guess one is up against reading .cnf files > generated by a variety of editors and sometimes written by hand. Hmmm... this actually sounds like a lot of fun! I'll start looking at this... *grin* From deirdre@deirdre.net Tue May 8 02:50:48 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Mon, 7 May 2001 18:50:48 -0700 Subject: [Tutor] Possible Useless Python Challenge. In-Reply-To: References: Message-ID: >On Sun, 6 May 2001, Tesla Coil wrote: > >> KiSS data sets are bundled using LZH compression, >> if there's a module for that, I haven't located it. > >I haven't found an LZH decompressor for Python. In fact, the GnomeKISS >people are depending on a separate LHA extraction program, so perhaps a >Python KISS program should delegate the handling of LZH compression to the >LHA utility. I've written both Lempel-Ziv and Huffman compressors and decompressors, but not LZH per se and not in Python. Given that Python has all the requisite bitwise operators, it would be possible, but it'd probably be better to write a wrapper for an existing set of C functions. -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From rob@jam.rr.com Tue May 8 04:38:00 2001 From: rob@jam.rr.com (Rob Andrews) Date: Mon, 07 May 2001 22:38:00 -0500 Subject: [Tutor] Possible Useless Python Challenge. References: Message-ID: <3AF76A18.DD866F80@jam.rr.com> Sometimes I barely understand a word of what's currently being discussed and still think it sounds nifty. This is such a time. hehe, Rob Deirdre Saoirse Moen wrote: > > >On Sun, 6 May 2001, Tesla Coil wrote: > > > >> KiSS data sets are bundled using LZH compression, > >> if there's a module for that, I haven't located it. > > > >I haven't found an LZH decompressor for Python. In fact, the GnomeKISS > >people are depending on a separate LHA extraction program, so perhaps a > >Python KISS program should delegate the handling of LZH compression to the > >LHA utility. > > I've written both Lempel-Ziv and Huffman compressors and > decompressors, but not LZH per se and not in Python. Given that > Python has all the requisite bitwise operators, it would be possible, > but it'd probably be better to write a wrapper for an existing set of > C functions. > > -- > _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net > "I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From julieta_rangel@hotmail.com Tue May 8 05:11:46 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Mon, 07 May 2001 23:11:46 -0500 Subject: [Tutor] obtaining an item from a list Message-ID: If I have a list, say l=[e,e,e,e], how can I give the first item in my list a name and print it? Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From bdupire@seatech.fau.edu Tue May 8 05:21:50 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Tue, 08 May 2001 00:21:50 -0400 Subject: [Tutor] obtaining an item from a list References: Message-ID: <3AF7745D.DD730F18@seatech.fau.edu> Is your list [e, e, e, e] or ['e','e','e','e'] ? A list can't be [e, e, e, e]. If you initialize it in this way, then - e - is replaced by its value... If you list is really [e, e, e, e] , let's say [10, 10, 10, 10], you can use either str(list[0]) or repr(list[0]). If i consider the second possibility, then you can use the string as a name --> list[0] is a string, right ? Hope this helps, Benoit Julieta Rangel wrote: > If I have a list, say l=[e,e,e,e], how can I give the first item in my list > a name and print it? > > Julieta > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From deirdre@deirdre.net Tue May 8 06:00:17 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Mon, 7 May 2001 22:00:17 -0700 Subject: [Tutor] Possible Useless Python Challenge. In-Reply-To: <3AF76A18.DD866F80@jam.rr.com> References: <3AF76A18.DD866F80@jam.rr.com> Message-ID: At 10:38 PM -0500 5/7/01, Rob Andrews wrote: >Sometimes I barely understand a word of what's currently being discussed >and still think it sounds nifty. This is such a time. Well, to grossly simplify the two types of compression: Huffman uses a variable number of bits to represent characters -- more common letters are represented by fewer bits; less common by more bits, on the theory that, on average, you'll save lots of bits. In its simplest form (but not a very common implementation these days), it uses three bits to store tree depth and the remaining bits to store tree location, i.e., for characters "etaion" appearing in descending of frequency: 000 e / \ 001 t a / \ / 010 i o n So, e = 000, t = 0011, a = 0010, i = 01011, o = 01010, n = 01001 In this form, you have to store the dictionary (i.e. the tree diagram) as a part of the compressed document, so the doc has to be fairly long (a few K) for the compression to be effective. Other forms use two trees and/or a known dictionary. Lempel-Ziv is compression based on pairs of characters that appear together commonly. http://www.faqs.org/faqs/compression-faq/part2/section-1.html > > I've written both Lempel-Ziv and Huffman compressors and > > decompressors, but not LZH per se and not in Python. Given that >> Python has all the requisite bitwise operators, it would be possible, >> but it'd probably be better to write a wrapper for an existing set of > > C functions. -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams From dyoo@hkn.eecs.berkeley.edu Tue May 8 06:05:26 2001 From: dyoo@hkn.eecs.berkeley.edu (Daniel Yoo) Date: Mon, 7 May 2001 22:05:26 -0700 (PDT) Subject: [Tutor] Possible Useless Python Challenge. [huffman encoding] In-Reply-To: <3AF76A18.DD866F80@jam.rr.com> Message-ID: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. Send mail to mime@docserver.cac.washington.edu for more info. --545289610-654942913-989298326=:5754 Content-Type: TEXT/PLAIN; charset=US-ASCII On Mon, 7 May 2001, Rob Andrews wrote: > Sometimes I barely understand a word of what's currently being discussed > and still think it sounds nifty. This is such a time. > > Deirdre Saoirse Moen wrote: > > > > >On Sun, 6 May 2001, Tesla Coil wrote: > > > > > >> KiSS data sets are bundled using LZH compression, > > >> if there's a module for that, I haven't located it. > > > > > >I haven't found an LZH decompressor for Python. In fact, the GnomeKISS > > >people are depending on a separate LHA extraction program, so perhaps a > > >Python KISS program should delegate the handling of LZH compression to the > > >LHA utility. > > > > I've written both Lempel-Ziv and Huffman compressors and > > decompressors, but not LZH per se and not in Python. Given that > > Python has all the requisite bitwise operators, it would be possible, > > but it'd probably be better to write a wrapper for an existing set of > > C functions. *laugh* I have a little bit of code that almost implements Huffman encoding. (VanL, this uses some of the tree code I mentioned earlier.) I was writing this during the afternoon. Coincidence, huh? I'll try to give the flavor of what Huffman encoding is. We need to give a little background though. [note, this is LONG.] When we represent letters --- one character strings --- Python (and mostly every other computer language) internally uses a numeric code called ASCII: American Standard Code for Information Interchange, to encode each character. Our computers are bit crunchers, so this means that every character we store needs to be saved as a number. For example, we could look at the string: "hello world" as a list of ASCII numbers: ### >>> map(ord, 'hello world') [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] ### but this is still one step removed from how computers REALLY represent characters; they represent them, not just in numeric form, but in crude, binary, base-two! Ones and zeros, and that's really weird when we first see it. Here's a small program that will try to reveal what's underneath: ### >>> def binaryStringHelper(n): ... if n == 0: return '' ... else: return binaryStringHelper(n >> 1) + str(n % 2) ... >>> def toBinaryString(n): ... if n == 0: return string.zfill(0, 8) ... return string.zfill(int(binaryStringHelper(n)), 8) ... >>> pprint.pprint(map(toBinaryString, range(10))) ['00000000', ## ...stands for 0 '00000001', ## ...stands for 1 '00000010', ## 2 '00000011', ## 3 '00000100', ## ... '00000101', '00000110', '00000111', '00001000', ## 8 '00001001'] ## 9 ### This is doing some hacky bit manipulation which isn't really important: the important thing is that this program above allows us to visualize all those one's and zero's that the computer actually uses to represent a character. We can apply this on our string: ### >>> pprint.pprint(map(toBinaryString, map(ord, 'hello world'))) ['01101000', '01100101', '01101100', '01101100', '01101111', '00100000', '01110111', '01101111', '01110010', '01101100', '01100100'] ### and this is how computers today truly store 'hello world' in its memory, as streams of ones and zeros. Every character is eight bits, so any string of length 'n' will take up '8*n' bits. Our small sentence, 'hello world', takes up 88 bits! Ok, this doesn't sound as world-threatening as we're making it out to be, but what is neat about Huffman encoding is that we can usually do much better than 88 bits. What Huffman realized is that we're not taking advantage of a certain curious property about human language: we use certain words over and over, certain letters over and over, and our language is fraught with repetitious repetition. What if we don't always represent a character by 8 bits, but by something that depends on how frequently the letter occurs in our language? Instead of having every letter be represented by eight bits, we can make a "variable length" encoding. That is, perhaps we can use the following code: 'h' ===> 0000 'w' ===> 0001 'd' ===> 0010 'e' ===> 0011 'o' ===> 01 'r' ===> 100 ' ' ===> 101 'l' ===> 11 That is, instead of using all eight bits on every letter, we can use a shorter binary sequence for really frequent characters, and longer codes for letters that we don't use as often. For letters that don't occur at all, we don't even need to give them a code. Huffman's encoding gives us a way of figuring out really good codes that do this for us. What this means is, that, instead of representing 'hello world' as: ### >>> string.join(map(toBinaryString, map(ord, 'hello world')), '') '0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100' ### we can do it like this: ### >>> code = {'h' : '0000', 'w' : '0001', 'd' : '0010', 'e' : '0011', 'o' : '01', 'r' : '101', ' ' : '101', 'l' : '11'} >>> string.join(map(lambda c: code[c], 'hello world'), '') '00000011111101101000101101110010' #### which is a heck of a lot shorter than what we had previously. This is the heart of Huffman encoding: to find a binary representation for each number so that a message doesn't take so much space to store. Of course this is handwavy, because whoever wants to read our message needs to have a copy of the dictionary! They need to be able to convert our binary message back into something readable, so we usually send off the dictionary alongside the encoded text. When a message gets large enough, though, that overhead becomes negigible compared to the amount of space we save. Finally, the code itself needs to guarantee that, given a bit string, there's only one way to rehydrate it back to it's nice spongy, wordy form. Not coinciently, Huffman encoding guarantees this for us. Really smart guy, and really neat algorithm. Does this make sense? I get the feeling I talked too much on this one already. *grin* The incomplete code to do Huffman encoding should be attached to this message. As soon as I get it in a nicer form, I'll send it off to Useless Python. --545289610-654942913-989298326=:5754 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="huffman.py" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename="huffman.py" IyEvdXNyL2Jpbi9lbnYgcHl0aG9uDQoNCiIiIlRyZWVzLCBCaW5hcnkgVHJl ZXMsIGFuZCBIdWZmbWFuIEVuY29kaW5nDQoNCkRhbm55IFlvbyAoZHlvb0Bo a24uZWVjcy5iZXJrZWxleS5lZHUpDQoNClRoZXNlIGNsYXNzZXMgZXhwbG9y ZSB0cmVlIHN0cnVjdHVyZXMgdXNlZCB0byBjcmVhdGUgSHVmZm1hbiB0cmVl cywgYQ0Kc3RhcGxlIG9mIGluZm9ybWF0aW9uIHRoZW9yeSBhbmQgY29tcHJl c3Npb24uICBQZXJoYXBzIEkgY2FuIHVzZSB0aGVzZQ0KY2xhc3NlcyBsYXRl ciB0byBwbGF5IGFyb3VuZCB3aXRoIHN1ZmZpeCB0cmVlcy4iIiINCg0KDQpj bGFzcyBUcmVlOg0KICAgICIiIkhlcmUncyBvbmUgd2F5IHRvIHJlcHJlc2Vu dCBnZW5lcmFsaXplZCB0cmVlcy4gIEEgdHJlZSBpcyBhDQogICAgc3RydWN0 dXJlIHRoYXQgaGFzIGEgZGF0dW0sIGFuZCBhbnkgbnVtYmVyIG9mIGNoaWxk cmVuLiIiIg0KICAgIGRlZiBfX2luaXRfXyhzZWxmLCBkYXR1bSwgY2hpbGRy ZW4gPSBOb25lKToNCiAgICAgICAgc2VsZi5fZGF0dW0gPSBkYXR1bQ0KICAg ICAgICBpZiBjaGlsZHJlbjoNCiAgICAgICAgICAgIHNlbGYuX2NoaWxkcmVu ID0gY2hpbGRyZW4NCiAgICAgICAgZWxzZToNCiAgICAgICAgICAgIHNlbGYu X2NoaWxkcmVuID0gW10NCg0KICAgIGRlZiBnZXREYXR1bShzZWxmKTogcmV0 dXJuIHNlbGYuX2RhdHVtDQoNCiAgICBkZWYgZ2V0Q2hpbGRyZW4oc2VsZik6 IHJldHVybiBzZWxmLl9jaGlsZHJlbg0KDQogICAgZGVmIGlzTGVhZihzZWxm KTogcmV0dXJuIGxlbihzZWxmLl9jaGlsZHJlbikgPT0gMA0KDQogICAgZGVm IGFkZENoaWxkKHNlbGYsIGNoaWxkKToNCiAgICAgICAgc2VsZi5fY2hpbGRy ZW4uYXBwZW5kKGNoaWxkKQ0KDQogICAgZGVmIF9fc3RyX18oc2VsZik6DQog ICAgICAgIHJldHVybiBzdHIoc2VsZi5fZGF0dW0pDQoNCiAgICBkZWYgX19y ZXByX18oc2VsZik6DQogICAgICAgIHJldHVybiAnVHJlZSglcywgJXMpJyAl IChyZXByKHNlbGYuX2RhdHVtKSwgcmVwcihzZWxmLl9jaGlsZHJlbikpDQoN Cg0KY2xhc3MgQmluYXJ5VHJlZToNCiAgICAiIiJBbiBpbXBsZW1lbnRhdGlv biBvZiBhIGJpbmFyeSB0cmVlLCBhIHN0cnVjdHVyZSB0aGF0IGhhcyBhDQog ICAgZGF0dW0sIGFuZCBhIGxlZnQgYW5kIHJpZ2h0IHN1YnRyZWUuIiIiDQog ICAgZGVmIF9faW5pdF9fKHNlbGYsIGRhdHVtLCBsZWZ0ID0gTm9uZSwgcmln aHQgPSBOb25lKToNCiAgICAgICAgc2VsZi5fZGF0dW0gPSBkYXR1bQ0KICAg ICAgICBzZWxmLl9sZWZ0LCBzZWxmLl9yaWdodCA9IGxlZnQsIHJpZ2h0DQoN CiAgICBkZWYgZ2V0RGF0dW0oc2VsZik6IHJldHVybiBzZWxmLl9kYXR1bQ0K DQogICAgZGVmIGdldExlZnQoc2VsZik6IHJldHVybiBzZWxmLl9sZWZ0DQoN CiAgICBkZWYgZ2V0UmlnaHQoc2VsZik6IHJldHVybiBzZWxmLl9yaWdodA0K ICAgIA0KICAgIGRlZiBpc0xlYWYoc2VsZik6DQogICAgICAgIHJldHVybiBz ZWxmLl9sZWZ0ID09IE5vbmUgYW5kIHNlbGYuX3JpZ2h0ID09IE5vbmUNCg0K ICAgIGRlZiBfX3N0cl9fKHNlbGYpOg0KICAgICAgICByZXR1cm4gc3RyKHNl bGYuX2RhdHVtKQ0KDQogICAgZGVmIF9fcmVwcl9fKHNlbGYpOg0KICAgICAg ICByZXR1cm4gJ0JpbmFyeVRyZWUoJXMsICVzLCAlcyknICUgXA0KICAgICAg ICAgICAgICAgdHVwbGUobWFwKHJlcHIsIFtzZWxmLl9kYXR1bSwgc2VsZi5f bGVmdCwgc2VsZi5fcmlnaHRdKSkNCg0KDQpkZWYgZ2V0SHVmZm1hblRyZWUo ZWxlbWVudHMpOg0KICAgICIiIkdpdmVuIGEgbGlzdCBvZiBlbGVtZW50cywg bGV0J3MgY29uc3RydWN0IGEgaHVmZm1hbiB0cmVlIHRoYXQNCiAgICBjYW4g YmUgdXNlZCB0byBwcm9kdWNlIGFuIG9wdGltYWwgYmluYXJ5IGNvZGUuIiIi DQogICAgZm9yZXN0ID0gZ2V0Rm9yZXN0RnJvbUVsZW1lbnRzKGVsZW1lbnRz KQ0KICAgIHdoaWxlIGxlbihmb3Jlc3QpID4gMToNCiAgICAgICAgdDEsIHQy ID0gZ2V0TWluaW1hbFR3b0VsZW1lbnRzKGZvcmVzdCkNCiAgICAgICAgZm9y ZXN0LnJlbW92ZSh0MSkNCiAgICAgICAgZm9yZXN0LnJlbW92ZSh0MikNCiAg ICAgICAgZm9yZXN0LmFwcGVuZChodWZmbWFuTWVyZ2VUcmVlcyh0MSwgdDIp KQ0KICAgIHJldHVybiBmb3Jlc3RbMF0NCg0KIyMjIyMjIyMjIyMjIyMjIyMj IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMj IyMjIyMjIw0KIyMgVGhlIGZvbGxvd2luZyBhcmUgaGVscGVyIGZ1bmN0aW9u cyBmb3IgZ2V0SHVmZm1hblRyZWUoKToNCg0KIyMgVGhlIGRhdHVtIG9mIGEg aHVmZm1hbiBub2RlIGNvbnNpc3RzIG9mIGEgbGFiZWwgYW5kIGl0cyB0b3Rh bA0KIyMgZnJlcXVlbmN5Lg0KZGVmIGRhdHVtTGFiZWwoZGF0dW0pOiByZXR1 cm4gZGF0dW1bMF0NCmRlZiBkYXR1bUZyZXEoZGF0dW0pOiByZXR1cm4gZGF0 dW1bMV0NCmRlZiBtYWtlRGF0dW0obGFiZWwsIGZyZXEpOiByZXR1cm4gKGxh YmVsLCBmcmVxKQ0KDQoNCiMjIFBlcmhhcHMgSSBzaG91bGQgZ2VuZXJhbGl6 ZSB0aGlzOyBpdCBpcyBwcmV0dHkgZGFybiB1c2VmdWwsIGlmIGENCiMjIGxp dHRsZSB1Z2x5Lg0KZGVmIGdldE1pbmltYWxUd29FbGVtZW50cyhmb3Jlc3Qp Og0KICAgICIiIlJldHVybiB0aGUgbGVhc3QgZnJlcXVlbnQgdHdvIGVsZW1l bnRzIG9mIGEgaHVmZm1hbiBmb3Jlc3QuIiIiDQogICAgbWluMSwgbWluMiA9 IGZvcmVzdFswOjJdDQogICAgaWYgZGF0dW1GcmVxKG1pbjIuZ2V0RGF0dW0o KSkgPiBkYXR1bUZyZXEobWluMS5nZXREYXR1bSgpKSA6DQogICAgICAgIG1p bjEsIG1pbjIgPSBtaW4yLCBtaW4xDQogICAgZm9yIHQgaW4gZm9yZXN0WzI6 XToNCiAgICAgICAgaWYgZGF0dW1GcmVxKHQuZ2V0RGF0dW0oKSkgPCBkYXR1 bUZyZXEobWluMS5nZXREYXR1bSgpKToNCiAgICAgICAgICAgIG1pbjEsIG1p bjIgPSB0LCBtaW4xDQogICAgICAgIGVsaWYgZGF0dW1GcmVxKHQuZ2V0RGF0 dW0oKSkgPCBkYXR1bUZyZXEobWluMi5nZXREYXR1bSgpKToNCiAgICAgICAg ICAgIG1pbjIgPSB0DQogICAgcmV0dXJuIG1pbjEsIG1pbjINCg0KDQpkZWYg aHVmZm1hbk1lcmdlVHJlZXModHJlZTEsIHRyZWUyKToNCiAgICAiIiJNZXJn ZSB0d28gaHVmZm1hbiB0cmVlcyBpbnRvIGEgbGFyZ2VyIHRyZWUuIiIiDQog ICAgbGFiZWwgPSBkYXR1bUxhYmVsKHRyZWUxLmdldERhdHVtKCkpICsgZGF0 dW1MYWJlbCh0cmVlMi5nZXREYXR1bSgpKQ0KICAgIGZyZXEgPSBkYXR1bUZy ZXEodHJlZTEuZ2V0RGF0dW0oKSkgKyBkYXR1bUZyZXEodHJlZTIuZ2V0RGF0 dW0oKSkNCiAgICByZXR1cm4gQmluYXJ5VHJlZShtYWtlRGF0dW0obGFiZWws IGZyZXEpLCB0cmVlMSwgdHJlZTIpDQoNCg0KZGVmIGdldEZvcmVzdEZyb21F bGVtZW50cyhlbGVtZW50cyk6DQogICAgIiIiR2l2ZXMgdXMgYSBmb3Jlc3Qg b2YgbGVhdmVzIHdob3NlIGRhdHVtcyBjb250YWluIGFuIGVsZW1lbnQgYW5k DQogICAgaXRzIGZyZXF1ZW5jeS4iIiINCiAgICBjb3VudHMgPSB7fQ0KICAg IGZvciBlIGluIGVsZW1lbnRzOg0KICAgICAgICBjb3VudHNbZV0gPSBjb3Vu dHMuZ2V0KGUsIDApICsgMQ0KICAgIGZvcmVzdCA9IFtdDQogICAgZm9yIGxl dHRlciwgZnJlcXVlbmN5IGluIGNvdW50cy5pdGVtcygpOg0KICAgICAgICBk YXR1bSA9IG1ha2VEYXR1bShbbGV0dGVyXSwgZnJlcXVlbmN5KQ0KICAgICAg ICBmb3Jlc3QuYXBwZW5kKEJpbmFyeVRyZWUoZGF0dW0sIE5vbmUsIE5vbmUp KQ0KICAgIHJldHVybiBmb3Jlc3QNCg0KDQojIyBIb3cgZG8gd2UgZHJhdyB0 cmVlcyBncmFwaGljYWxseT8gIEFuZCBuaWNlbHk/DQo= --545289610-654942913-989298326=:5754-- From juno@gamefire.com Tue May 8 06:56:14 2001 From: juno@gamefire.com (juno@gamefire.com) Date: Mon, 7 May 2001 22:56:14 -0700 Subject: [Tutor] Possible Useless Python Challenge. [huffman encoding] In-Reply-To: Message-ID: Daniel, You rock! I thought that LZH and LHA was an old dead compression algorithm that only hackers still used ;) -----Original Message----- From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of Daniel Yoo Sent: Monday, May 07, 2001 10:05 PM To: Rob Andrews Cc: Deirdre Saoirse Moen; tutor@python.org Subject: Re: [Tutor] Possible Useless Python Challenge. [huffman encoding] On Mon, 7 May 2001, Rob Andrews wrote: > Sometimes I barely understand a word of what's currently being discussed > and still think it sounds nifty. This is such a time. > > Deirdre Saoirse Moen wrote: > > > > >On Sun, 6 May 2001, Tesla Coil wrote: > > > > > >> KiSS data sets are bundled using LZH compression, > > >> if there's a module for that, I haven't located it. > > > > > >I haven't found an LZH decompressor for Python. In fact, the GnomeKISS > > >people are depending on a separate LHA extraction program, so perhaps a > > >Python KISS program should delegate the handling of LZH compression to the > > >LHA utility. > > > > I've written both Lempel-Ziv and Huffman compressors and > > decompressors, but not LZH per se and not in Python. Given that > > Python has all the requisite bitwise operators, it would be possible, > > but it'd probably be better to write a wrapper for an existing set of > > C functions. *laugh* I have a little bit of code that almost implements Huffman encoding. (VanL, this uses some of the tree code I mentioned earlier.) I was writing this during the afternoon. Coincidence, huh? I'll try to give the flavor of what Huffman encoding is. We need to give a little background though. [note, this is LONG.] When we represent letters --- one character strings --- Python (and mostly every other computer language) internally uses a numeric code called ASCII: American Standard Code for Information Interchange, to encode each character. Our computers are bit crunchers, so this means that every character we store needs to be saved as a number. For example, we could look at the string: "hello world" as a list of ASCII numbers: ### >>> map(ord, 'hello world') [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] ### but this is still one step removed from how computers REALLY represent characters; they represent them, not just in numeric form, but in crude, binary, base-two! Ones and zeros, and that's really weird when we first see it. Here's a small program that will try to reveal what's underneath: ### >>> def binaryStringHelper(n): ... if n == 0: return '' ... else: return binaryStringHelper(n >> 1) + str(n % 2) ... >>> def toBinaryString(n): ... if n == 0: return string.zfill(0, 8) ... return string.zfill(int(binaryStringHelper(n)), 8) ... >>> pprint.pprint(map(toBinaryString, range(10))) ['00000000', ## ...stands for 0 '00000001', ## ...stands for 1 '00000010', ## 2 '00000011', ## 3 '00000100', ## ... '00000101', '00000110', '00000111', '00001000', ## 8 '00001001'] ## 9 ### This is doing some hacky bit manipulation which isn't really important: the important thing is that this program above allows us to visualize all those one's and zero's that the computer actually uses to represent a character. We can apply this on our string: ### >>> pprint.pprint(map(toBinaryString, map(ord, 'hello world'))) ['01101000', '01100101', '01101100', '01101100', '01101111', '00100000', '01110111', '01101111', '01110010', '01101100', '01100100'] ### and this is how computers today truly store 'hello world' in its memory, as streams of ones and zeros. Every character is eight bits, so any string of length 'n' will take up '8*n' bits. Our small sentence, 'hello world', takes up 88 bits! Ok, this doesn't sound as world-threatening as we're making it out to be, but what is neat about Huffman encoding is that we can usually do much better than 88 bits. What Huffman realized is that we're not taking advantage of a certain curious property about human language: we use certain words over and over, certain letters over and over, and our language is fraught with repetitious repetition. What if we don't always represent a character by 8 bits, but by something that depends on how frequently the letter occurs in our language? Instead of having every letter be represented by eight bits, we can make a "variable length" encoding. That is, perhaps we can use the following code: 'h' ===> 0000 'w' ===> 0001 'd' ===> 0010 'e' ===> 0011 'o' ===> 01 'r' ===> 100 ' ' ===> 101 'l' ===> 11 That is, instead of using all eight bits on every letter, we can use a shorter binary sequence for really frequent characters, and longer codes for letters that we don't use as often. For letters that don't occur at all, we don't even need to give them a code. Huffman's encoding gives us a way of figuring out really good codes that do this for us. What this means is, that, instead of representing 'hello world' as: ### >>> string.join(map(toBinaryString, map(ord, 'hello world')), '') '011010000110010101101100011011000110111100100000011101110110111101110010011 0110001100100' ### we can do it like this: ### >>> code = {'h' : '0000', 'w' : '0001', 'd' : '0010', 'e' : '0011', 'o' : '01', 'r' : '101', ' ' : '101', 'l' : '11'} >>> string.join(map(lambda c: code[c], 'hello world'), '') '00000011111101101000101101110010' #### which is a heck of a lot shorter than what we had previously. This is the heart of Huffman encoding: to find a binary representation for each number so that a message doesn't take so much space to store. Of course this is handwavy, because whoever wants to read our message needs to have a copy of the dictionary! They need to be able to convert our binary message back into something readable, so we usually send off the dictionary alongside the encoded text. When a message gets large enough, though, that overhead becomes negigible compared to the amount of space we save. Finally, the code itself needs to guarantee that, given a bit string, there's only one way to rehydrate it back to it's nice spongy, wordy form. Not coinciently, Huffman encoding guarantees this for us. Really smart guy, and really neat algorithm. Does this make sense? I get the feeling I talked too much on this one already. *grin* The incomplete code to do Huffman encoding should be attached to this message. As soon as I get it in a nicer form, I'll send it off to Useless Python. From ppathiyi@cisco.com Tue May 8 09:00:06 2001 From: ppathiyi@cisco.com (Praveen Pathiyil) Date: Tue, 8 May 2001 13:30:06 +0530 Subject: [Tutor] Python availability on VxWorks Message-ID: <032a01c0d794$e834a5f0$37ef87c0@ppathiyipc> This is a multi-part message in MIME format. ------=_NextPart_000_0327_01C0D7C2.FE99BF50 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable HI, Is python interpreter available for VxWorks ? I have seen = mentions about python on Unix, Windows and MAC OSs. But not on VxWorks. = Can anybody throw some light on this ? TIA, Praveen. ------=_NextPart_000_0327_01C0D7C2.FE99BF50 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
HI,
        Is=20 python interpreter available for VxWorks ? I have seen mentions about = python on=20 Unix, Windows and MAC OSs. But not on VxWorks. Can anybody throw some = light on=20 this ?
 
TIA,
Praveen.
------=_NextPart_000_0327_01C0D7C2.FE99BF50-- From deirdre@deirdre.net Tue May 8 09:12:50 2001 From: deirdre@deirdre.net (Deirdre Saoirse Moen) Date: Tue, 8 May 2001 01:12:50 -0700 Subject: [Tutor] Python availability on VxWorks In-Reply-To: <032a01c0d794$e834a5f0$37ef87c0@ppathiyipc> References: <032a01c0d794$e834a5f0$37ef87c0@ppathiyipc> Message-ID: --============_-1222812916==_ma============ Content-Type: text/plain; charset="us-ascii" ; format="flowed" >HI, >Is python interpreter available for VxWorks ? I have seen mentions >about python on Unix, Windows and MAC OSs. But not on VxWorks. Can >anybody throw some light on this ? vxWorks is a Unix derivative. That said, I don't know a whole lot about it. -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams --============_-1222812916==_ma============ Content-Type: text/html; charset="us-ascii" Re: [Tutor] Python availability on VxWorks
HI,
Is python interpreter available for VxWorks ? I have seen mentions about python on Unix, Windows and MAC OSs. But not on VxWorks. Can anybody throw some light on this ?

vxWorks is a Unix derivative. That said, I don't know a whole lot about it.
--============_-1222812916==_ma============-- From lonetwin@yahoo.com Tue May 8 09:50:43 2001 From: lonetwin@yahoo.com (steve) Date: Tue, 8 May 2001 14:20:43 +0530 Subject: [Tutor] Possible Useless Python Challenge. [huffman encoding] In-Reply-To: References: Message-ID: <01050814204300.02674@mercury.in.cqsl.com> Hey Dan, Thanx, Every day I learn something new, an' I just finished today's quot= a !!! Peace Steve P.S: U pretty good at xplainin' stuff, did n e body ever tell u that ??? On Tuesday 08 May 2001 10:35, you wrote: > > On Mon, 7 May 2001, Rob Andrews wrote: > > Sometimes I barely understand a word of what's currently being discus= sed > > and still think it sounds nifty. This is such a time. > > > > Deirdre Saoirse Moen wrote: > > > >On Sun, 6 May 2001, Tesla Coil wrote: > > > >> KiSS data sets are bundled using LZH compression, > > > >> if there's a module for that, I haven't located it. > > > > > > > >I haven't found an LZH decompressor for Python. In fact, the > > > > GnomeKISS people are depending on a separate LHA extraction progr= am, > > > > so perhaps a Python KISS program should delegate the handling of = LZH > > > > compression to the LHA utility. > > > > > > I've written both Lempel-Ziv and Huffman compressors and > > > decompressors, but not LZH per se and not in Python. Given that > > > Python has all the requisite bitwise operators, it would be possibl= e, > > > but it'd probably be better to write a wrapper for an existing set = of > > > C functions. > > *laugh* I have a little bit of code that almost implements Huffman > encoding. (VanL, this uses some of the tree code I mentioned earlier.) > I was writing this during the afternoon. Coincidence, huh? > > I'll try to give the flavor of what Huffman encoding is. We need to gi= ve > a little background though. [note, this is LONG.] > > When we represent letters --- one character strings --- Python (and mos= tly > every other computer language) internally uses a numeric code called > ASCII: American Standard Code for Information Interchange, to encode ea= ch > character. > > Our computers are bit crunchers, so this means that every character we > store needs to be saved as a number. For example, we could look at the > string: > > "hello world" > > as a list of ASCII numbers: > > ### > > >>> map(ord, 'hello world') > > [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] > ### > > but this is still one step removed from how computers REALLY represent > characters; they represent them, not just in numeric form, but in crude= , > binary, base-two! Ones and zeros, and that's really weird when we firs= t > see it. Here's a small program that will try to reveal what's undernea= th: > > ### > > >>> def binaryStringHelper(n): > > ... if n =3D=3D 0: return '' > ... else: return binaryStringHelper(n >> 1) + str(n % 2) > ... > > >>> def toBinaryString(n): > > ... if n =3D=3D 0: return string.zfill(0, 8) > ... return string.zfill(int(binaryStringHelper(n)), 8) > ... > > >>> pprint.pprint(map(toBinaryString, range(10))) > > ['00000000', ## ...stands for 0 > '00000001', ## ...stands for 1 > '00000010', ## 2 > '00000011', ## 3 > '00000100', ## ... > '00000101', > '00000110', > '00000111', > '00001000', ## 8 > '00001001'] ## 9 > ### > > This is doing some hacky bit manipulation which isn't really important: > the important thing is that this program above allows us to visualize a= ll > those one's and zero's that the computer actually uses to represent a > character. We can apply this on our string: > > > ### > > >>> pprint.pprint(map(toBinaryString, map(ord, 'hello world'))) > > ['01101000', > '01100101', > '01101100', > '01101100', > '01101111', > '00100000', > '01110111', > '01101111', > '01110010', > '01101100', > '01100100'] > ### > > and this is how computers today truly store 'hello world' in its memory= , > as streams of ones and zeros. Every character is eight bits, so any > string of length 'n' will take up '8*n' bits. Our small sentence, 'hel= lo > world', takes up 88 bits! > > > Ok, this doesn't sound as world-threatening as we're making it out to b= e, > but what is neat about Huffman encoding is that we can usually do much > better than 88 bits. > > What Huffman realized is that we're not taking advantage of a certain > curious property about human language: we use certain words over and ov= er, > certain letters over and over, and our language is fraught with > repetitious repetition. What if we don't always represent a character b= y 8 > bits, but by something that depends on how frequently the letter occurs= in > our language? Instead of having every letter be represented by eight > bits, we can make a "variable length" encoding. That is, perhaps we ca= n > use the following code: > > 'h' =3D=3D=3D> 0000 > 'w' =3D=3D=3D> 0001 > 'd' =3D=3D=3D> 0010 > 'e' =3D=3D=3D> 0011 > 'o' =3D=3D=3D> 01 > 'r' =3D=3D=3D> 100 > ' ' =3D=3D=3D> 101 > 'l' =3D=3D=3D> 11 > > That is, instead of using all eight bits on every letter, we can use a > shorter binary sequence for really frequent characters, and longer code= s > for letters that we don't use as often. For letters that don't occur a= t > all, we don't even need to give them a code. Huffman's encoding gives = us > a way of figuring out really good codes that do this for us. What this > means is, that, instead of representing 'hello world' as: > > ### > > >>> string.join(map(toBinaryString, map(ord, 'hello world')), '') > > '0110100001100101011011000110110001101111001000000111011101101111011100= 1001 >10110001100100' ### > > > we can do it like this: > > ### > > >>> code =3D {'h' : '0000', 'w' : '0001', 'd' : '0010', 'e' : '0011', > > 'o' : '01', 'r' : '101', ' ' : '101', 'l' : '11'} > > >>> string.join(map(lambda c: code[c], 'hello world'), '') > > '00000011111101101000101101110010' > #### > > which is a heck of a lot shorter than what we had previously. This is = the > heart of Huffman encoding: to find a binary representation for each num= ber > so that a message doesn't take so much space to store. > > Of course this is handwavy, because whoever wants to read our message > needs to have a copy of the dictionary! They need to be able to conver= t > our binary message back into something readable, so we usually send off > the dictionary alongside the encoded text. When a message gets large > enough, though, that overhead becomes negigible compared to the amount = of > space we save. > > Finally, the code itself needs to guarantee that, given a bit string, > there's only one way to rehydrate it back to it's nice spongy, wordy fo= rm. > Not coinciently, Huffman encoding guarantees this for us. Really smart > guy, and really neat algorithm. > > Does this make sense? I get the feeling I talked too much on this one > already. *grin* > > > The incomplete code to do Huffman encoding should be attached to this > message. As soon as I get it in a nicer form, I'll send it off to Usel= ess > Python. ---------------------------------------- Content-Type: TEXT/PLAIN; charset=3D"US-ASCII"; name=3D"huffman.py" Content-Transfer-Encoding: BASE64 Content-Description:=20 ---------------------------------------- --=20 |||||||||||||||||||||| |||||||||#####|||||||| ||||||||#######||||||| ||||||||# O O #||||||| ||||||||#\ ~ /#||||||| ||||||##||\_/||##||||| |||||#||||||||||##|||| ||||#||||||||||||##||| ||||#|||||||||||||##||=09 |||/\##|||||||||##/\||=09 |/ \#########/ \=09 |\ \#######/ /=09 ||\____/#######\____/|=09 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=09 "Unfortunately, those people who have nothing better to do than post on t= he Internet all day long are rarely the ones who have the most insights." =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D From cooler12001@yahoo.com Tue May 8 10:25:35 2001 From: cooler12001@yahoo.com (Matthews James) Date: Tue, 8 May 2001 02:25:35 -0700 (PDT) Subject: [Tutor] help with files Message-ID: <20010508092535.2976.qmail@web11405.mail.yahoo.com> Ok I have a .txt file that is something like this: ##################################################### [backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace]wds[backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace][backspace]\w\des\s jumper eat the ball [backspace][backspace][backspace][backspace]jumper ####################################################### I am want help with changing the looks of it. like at a [backspace] im wanting to have a '\n' after it so that it will change lines. and the letters or words im wanting to stay on the same line. Can anyone help me? I know how to open a file in python but not change it I know that anyone that looks at this question is gonna say huh? this is all i know about this stuff: #################################################### openfile = open(filename,'{what do i put here}') #################################################### Thanx and Thanx to all of you who helped me out on my other lame questions. James __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ From wheelege@tsn.cc Tue May 8 12:06:29 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Tue, 8 May 2001 21:06:29 +1000 Subject: [Tutor] Python CGI-HTML editor References: <200105070938_MC2-D005-A842@compuserve.com> Message-ID: <00dd01c0d7ae$f3f6e820$0200a8c0@ACE> >I have coded an HTML online editor with the help of several Python CGI >scripts. I´m now faced woth the problem of image insertion, I know how to >upload files per CGI-Python to a server, but I still have 1 complicated >hurdle: > >1. Is it possilbe to start a file upload AND send text data from a HTML >form at the same time? Well, I don't know if anybody else has answered you yet, but you could take a look at threading. Something like... import thread def UploadStuff(file, form, server): thread.start_new_thread(UploadFile, (file, server)) thread.start_new_thread(UploadForm, (form, server)) def UploadFile(file, server): def UploadForm(file, server): As you can probably tell, I am not fluent in CGI - yet. But I think this should work if the server supports multiple connections from the same IP address. Hope that helps, Glen. From rob@jam.rr.com Tue May 8 12:19:32 2001 From: rob@jam.rr.com (Rob Andrews) Date: Tue, 08 May 2001 06:19:32 -0500 Subject: [Tutor] Possible Useless Python Challenge. [huffman encoding] References: Message-ID: <3AF7D644.6219F546@jam.rr.com> I'm so glad Danny Yoo became involved in programming instead of competing on the karaoke circuit or something. Thanks to Danny and Deirdre both for bringing the subject more into the light. Rob Daniel Yoo wrote: > > On Mon, 7 May 2001, Rob Andrews wrote: > > > Sometimes I barely understand a word of what's currently being discussed > > and still think it sounds nifty. This is such a time. > > > > Deirdre Saoirse Moen wrote: > > > > > > >On Sun, 6 May 2001, Tesla Coil wrote: > > > > > > > >> KiSS data sets are bundled using LZH compression, > > > >> if there's a module for that, I haven't located it. > > > > > > > >I haven't found an LZH decompressor for Python. In fact, the GnomeKISS > > > >people are depending on a separate LHA extraction program, so perhaps a > > > >Python KISS program should delegate the handling of LZH compression to the > > > >LHA utility. > > > > > > I've written both Lempel-Ziv and Huffman compressors and > > > decompressors, but not LZH per se and not in Python. Given that > > > Python has all the requisite bitwise operators, it would be possible, > > > but it'd probably be better to write a wrapper for an existing set of > > > C functions. > > *laugh* I have a little bit of code that almost implements Huffman > encoding. (VanL, this uses some of the tree code I mentioned earlier.) > I was writing this during the afternoon. Coincidence, huh? > > I'll try to give the flavor of what Huffman encoding is. We need to give > a little background though. [note, this is LONG.] > > When we represent letters --- one character strings --- Python (and mostly > every other computer language) internally uses a numeric code called > ASCII: American Standard Code for Information Interchange, to encode each > character. > > Our computers are bit crunchers, so this means that every character we > store needs to be saved as a number. For example, we could look at the > string: > > "hello world" > > as a list of ASCII numbers: > > ### > >>> map(ord, 'hello world') > [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] > ### > > but this is still one step removed from how computers REALLY represent > characters; they represent them, not just in numeric form, but in crude, > binary, base-two! Ones and zeros, and that's really weird when we first > see it. Here's a small program that will try to reveal what's underneath: > > ### > >>> def binaryStringHelper(n): > ... if n == 0: return '' > ... else: return binaryStringHelper(n >> 1) + str(n % 2) > ... > >>> def toBinaryString(n): > ... if n == 0: return string.zfill(0, 8) > ... return string.zfill(int(binaryStringHelper(n)), 8) > ... > >>> pprint.pprint(map(toBinaryString, range(10))) > ['00000000', ## ...stands for 0 > '00000001', ## ...stands for 1 > '00000010', ## 2 > '00000011', ## 3 > '00000100', ## ... > '00000101', > '00000110', > '00000111', > '00001000', ## 8 > '00001001'] ## 9 > ### > > This is doing some hacky bit manipulation which isn't really important: > the important thing is that this program above allows us to visualize all > those one's and zero's that the computer actually uses to represent a > character. We can apply this on our string: > > ### > >>> pprint.pprint(map(toBinaryString, map(ord, 'hello world'))) > ['01101000', > '01100101', > '01101100', > '01101100', > '01101111', > '00100000', > '01110111', > '01101111', > '01110010', > '01101100', > '01100100'] > ### > > and this is how computers today truly store 'hello world' in its memory, > as streams of ones and zeros. Every character is eight bits, so any > string of length 'n' will take up '8*n' bits. Our small sentence, 'hello > world', takes up 88 bits! > > Ok, this doesn't sound as world-threatening as we're making it out to be, > but what is neat about Huffman encoding is that we can usually do much > better than 88 bits. > > What Huffman realized is that we're not taking advantage of a certain > curious property about human language: we use certain words over and over, > certain letters over and over, and our language is fraught with > repetitious repetition. What if we don't always represent a character by 8 > bits, but by something that depends on how frequently the letter occurs in > our language? Instead of having every letter be represented by eight > bits, we can make a "variable length" encoding. That is, perhaps we can > use the following code: > > 'h' ===> 0000 > 'w' ===> 0001 > 'd' ===> 0010 > 'e' ===> 0011 > 'o' ===> 01 > 'r' ===> 100 > ' ' ===> 101 > 'l' ===> 11 > > That is, instead of using all eight bits on every letter, we can use a > shorter binary sequence for really frequent characters, and longer codes > for letters that we don't use as often. For letters that don't occur at > all, we don't even need to give them a code. Huffman's encoding gives us > a way of figuring out really good codes that do this for us. What this > means is, that, instead of representing 'hello world' as: > > ### > >>> string.join(map(toBinaryString, map(ord, 'hello world')), '') > '0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100' > ### > > we can do it like this: > > ### > >>> code = {'h' : '0000', 'w' : '0001', 'd' : '0010', 'e' : '0011', > 'o' : '01', 'r' : '101', ' ' : '101', 'l' : '11'} > >>> string.join(map(lambda c: code[c], 'hello world'), '') > '00000011111101101000101101110010' > #### > > which is a heck of a lot shorter than what we had previously. This is the > heart of Huffman encoding: to find a binary representation for each number > so that a message doesn't take so much space to store. > > Of course this is handwavy, because whoever wants to read our message > needs to have a copy of the dictionary! They need to be able to convert > our binary message back into something readable, so we usually send off > the dictionary alongside the encoded text. When a message gets large > enough, though, that overhead becomes negigible compared to the amount of > space we save. > > Finally, the code itself needs to guarantee that, given a bit string, > there's only one way to rehydrate it back to it's nice spongy, wordy form. > Not coinciently, Huffman encoding guarantees this for us. Really smart > guy, and really neat algorithm. > > Does this make sense? I get the feeling I talked too much on this one > already. *grin* > > The incomplete code to do Huffman encoding should be attached to this > message. As soon as I get it in a nicer form, I'll send it off to Useless > Python. > > ------------------------------------------------------------------------ > Name: huffman.py > huffman.py Type: Plain Text (TEXT/PLAIN) > Encoding: BASE64 -- Useless Python! If your Python is this useless, we need you. http://www.lowerstandard.com/python/pythonsource.html From wheelege@tsn.cc Tue May 8 13:09:08 2001 From: wheelege@tsn.cc (Glen Wheeler) Date: Tue, 8 May 2001 22:09:08 +1000 Subject: [Tutor] com...? Message-ID: <01c501c0d7b7$afe9dc60$0200a8c0@ACE> This is a multi-part message in MIME format. ------=_NextPart_000_01C2_01C0D80B.81080440 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hey all, Ok, maybe I'm just really unco at finding documentation, but this = mythical com module for win32...I can't find it for the life of me. I = am planning on controlling internet explorer using it (from within a = python script). A link to some documentation would be nice. Thanks, Glen. ------=_NextPart_000_01C2_01C0D80B.81080440 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
  Hey all,
 
  Ok, maybe I'm just really unco at finding documentation, but = this=20 mythical com module for win32...I can't find it for the life of = me.  I am=20 planning on controlling internet explorer using it (from within a python = script).
  A link to some documentation would be nice.
 
  Thanks,
  Glen.
------=_NextPart_000_01C2_01C0D80B.81080440-- From parth.malwankar@wipro.com Tue May 8 13:18:49 2001 From: parth.malwankar@wipro.com (Parth Malwankar) Date: Tue, 8 May 2001 17:48:49 +0530 Subject: [Tutor] Python availability on VxWorks In-Reply-To: ; from Deirdre Saoirse Moen on Tue, May 08, 2001 at 01:12:50AM -0700 References: <032a01c0d794$e834a5f0$37ef87c0@ppathiyipc> Message-ID: <20010508174849.C4304@wipro.wipsys.sequent.com> http://daikon.tuc.noao.edu/python/ Contains info about building python for vxWorks. I havent tried it though. Regards, Parth On Tue, May 08, 2001 at 01:12:50AM -0700, Deirdre Saoirse Moen wrote: >>HI, >>Is python interpreter available for VxWorks ? I have seen mentions >>about python on Unix, Windows and MAC OSs. But not on VxWorks. Can >>anybody throw some light on this ? > >vxWorks is a Unix derivative. That said, I don't know a whole lot about it. > >-- >_Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net >"I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams From scarblac@pino.selwerd.nl Tue May 8 13:25:01 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 8 May 2001 14:25:01 +0200 Subject: [Tutor] com...? In-Reply-To: <01c501c0d7b7$afe9dc60$0200a8c0@ACE>; from wheelege@tsn.cc on Tue, May 08, 2001 at 10:09:08PM +1000 References: <01c501c0d7b7$afe9dc60$0200a8c0@ACE> Message-ID: <20010508142501.A7353@pino.selwerd.nl> On 0, Glen Wheeler wrote: > Ok, maybe I'm just really unco at finding documentation, but this mythical com module for win32...I can't find it for the life of me. I am planning on controlling internet explorer using it (from within a python script). > A link to some documentation would be nice. You need the Windows extensions, they're not in the standard Python distribution. See http://aspn.activestate.com/ASPN/Downloads/ActivePython/Extensions/Win32all ActiveState also has their own Python distribution that includes the Windows things, if you like that better. I don't know where good online information is (I don't do Windows), but the book "Python Programming on Win32" is supposed to be pretty good at explaining COM with Python. -- Remco Gerlich From julieta_rangel@hotmail.com Tue May 8 13:33:08 2001 From: julieta_rangel@hotmail.com (Julieta Rangel) Date: Tue, 08 May 2001 07:33:08 -0500 Subject: [Tutor] selecting specific items from a list Message-ID: Let's say I have the following list: [(3,3),(2,0),(5,5), (1,1), (4,5), (a,a), (a,e), (b,b), (c,d)] How can I tell the computer to return to me only those items in the list for which x==y. That is, [(3,3), (5,5), (1,1), (a,a), (b,b)]. It's a dumb question, but somebody's got to ask it :) Julieta _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From ppathiyi@cisco.com Tue May 8 13:44:04 2001 From: ppathiyi@cisco.com (Praveen Pathiyil) Date: Tue, 8 May 2001 18:14:04 +0530 Subject: [Tutor] selecting specific items from a list References: Message-ID: <03b601c0d7bc$90e7aea0$37ef87c0@ppathiyipc> I feel that the following should do the job for you... list1 = [(3,3),(2,0),(5,5), (1,1), (4,5), ('a','a'), ('a','e'), ('b','b'), ('c','d')] eq_list = [] for (x,y) in list1: if x==y: eq_list.append(x,y) Regards, Praveen. ----- Original Message ----- From: "Julieta Rangel" To: Sent: Tuesday, May 08, 2001 6:03 PM Subject: [Tutor] selecting specific items from a list > Let's say I have the following list: > > [(3,3),(2,0),(5,5), (1,1), (4,5), (a,a), (a,e), (b,b), (c,d)] > > How can I tell the computer to return to me only those items in the list for > which x==y. That is, [(3,3), (5,5), (1,1), (a,a), (b,b)]. > > It's a dumb question, but somebody's got to ask it :) > > Julieta > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From scarblac@pino.selwerd.nl Tue May 8 13:49:59 2001 From: scarblac@pino.selwerd.nl (Remco Gerlich) Date: Tue, 8 May 2001 14:49:59 +0200 Subject: [Tutor] selecting specific items from a list In-Reply-To: ; from julieta_rangel@hotmail.com on Tue, May 08, 2001 at 07:33:08AM -0500 References: Message-ID: <20010508144958.A7908@pino.selwerd.nl> On 0, Julieta Rangel wrote: > Let's say I have the following list: > > [(3,3),(2,0),(5,5), (1,1), (4,5), (a,a), (a,e), (b,b), (c,d)] > > How can I tell the computer to return to me only those items in the list for > which x==y. That is, [(3,3), (5,5), (1,1), (a,a), (b,b)]. > > It's a dumb question, but somebody's got to ask it :) It's easiest with list comprehensions, but they're new in 2.0: (I'm calling your list 'tuplist') result = [tup for tup in tuplist if tup[0] == tup[1]] That is, the list of tups, taken from tuplist, where tup[0] equals tup[1]. (the list comprehension notation was originally inspired by set notation in math). In older versions, you'd use filter. First you define a function that's true for the tuples you want, then you filter the list using it: def test_tuple(tup): return tup[0] == tup[1] result = filter(test_tuple, tuplist) Some people would use a lambda to write that, so there's no need to name the temporary function, and it becomes one line again: result = filter(lambda tup: tup[0] == tup[1], tuplist) -- Remco Gerlich From bdupire@seatech.fau.edu Tue May 8 15:11:38 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Tue, 08 May 2001 10:11:38 -0400 Subject: [Tutor] Python internals. Message-ID: <3AF7FE99.5B4FF279@seatech.fau.edu> it's up to me to ask something to the Python gurus out there... One of the BIG difference between Python and C++, except for speed, is that Python is dynamic and C++ static. Thus, i can define in Python new functions on the fly and take advantage of features such as myString= 'a=19+3' exec(myString) But myString could also be a new function. My question is the following: how does Python internally create a new function dynamically, although it's implemented in C, where such features are not allowed (static) ? How are Python functions implemented in C? My question might have no sense, i know. . . Anyway.. i am just curious... -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From tescoil@irtc.net Tue May 8 15:45:01 2001 From: tescoil@irtc.net (Tesla Coil) Date: Tue, 08 May 2001 09:45:01 -0500 Subject: [Tutor] Possible Useless Python Challenge. References: Message-ID: <3AF8066D.33C13F3E@irtc.net> On 7 May 2001, Daniel Yoo wrote: > I haven't found an LZH decompressor for Python. In fact, > the GnomeKISS people are depending on a separate LHA > extraction program, so perhaps a Python KISS program > should delegate the handling of LZH compression to the > LHA utility. I was going to mention LHA, but the TODO file included with GnomeKiss source lists to "do LZH natively, and generally support it better"--from which I infer it's been judged not the best approach. A C extension module to handle LZH might assist the Python World Domination campaign in Japan. Doesn't look like Ruby has a library for it yet either. >> I suppose that a cel file decoder could be cooked up >> using Python Imaging Library, but I've no experience >> in that department at all. Other than that, I guess >> one is up against reading .cnf files generated by a >> variety of editors and sometimes written by hand. > > Hmmm... this actually sounds like a lot of fun! I'll > start looking at this... *grin* I begin to get the feeling if I'd posted the message to c.l.py, there'd be PyKiss v0.2 by Friday... :} From randrews@planhouse.com Tue May 8 16:03:19 2001 From: randrews@planhouse.com (Rob Andrews) Date: Tue, 8 May 2001 10:03:19 -0500 Subject: [Tutor] Possible Useless Python Challenge. In-Reply-To: <3AF8066D.33C13F3E@irtc.net> Message-ID: <001101c0d7d0$04eec460$de00a8c0@planhouse5> > I begin to get the feeling if I'd posted the message > to c.l.py, there'd be PyKiss v0.2 by Friday... :} But the Python Tutor list is where the real action is! This is the best resource I've seen yet for newbies to see why Python's so exciting. Rob _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor From tescoil@irtc.net Tue May 8 16:20:01 2001 From: tescoil@irtc.net (Tesla Coil) Date: Tue, 08 May 2001 10:20:01 -0500 Subject: [Tutor] Possible Useless Python Challenge. [huffman encoding] References: Message-ID: <3AF80EA1.A86D5028@irtc.net> On 7 May 2001, Daniel Yoo wrote: > What Huffman realized is that we're not taking advantage > of a certain curious property about human language: we=20 > use certain words over and over, certain letters over=20 > and over, and our language is fraught with repetitious > repetition. What if we don't always represent a=20 > character by 8 bits, but by something that depends > on how frequently the letter occurs in our language? > Instead of having every letter be represented by=20 > eight bits, we can make a "variable length" encoding. > That is, perhaps we can use the following code: > > 'h' =3D=3D=3D> 0000 > 'w' =3D=3D=3D> 0001 > 'd' =3D=3D=3D> 0010 > 'e' =3D=3D=3D> 0011 > 'o' =3D=3D=3D> 01 > 'r' =3D=3D=3D> 100 > ' ' =3D=3D=3D> 101 > 'l' =3D=3D=3D> 11 Incidentally, same principle used by an early binary compression scheme known as Morse code: 'h' =3D=3D=3D> 0000 'w' =3D=3D=3D> 011 'd' =3D=3D=3D> 100 'e' =3D=3D=3D> 0 'o' =3D=3D=3D> 111 'r' =3D=3D=3D> 010 ' ' =3D=3D=3D> 'l' =3D=3D=3D> 0100 "Plus =E7a change...," I guess. From alan.gauld@bt.com Tue May 8 17:19:03 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 8 May 2001 17:19:03 +0100 Subject: [Tutor] com...? Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D74D@mbtlipnt02.btlabs.bt.co.uk> ------_=_NextPart_001_01C0D7DA.98E2B2D0 Content-type: text/plain; charset="iso-8859-1" Ok, maybe I'm just really unco at finding documentation, but this mythical com module for win32...I can't find it for the life of me. I am planning on controlling internet explorer using it Assuming you have BeOpen Python 2 and installed winall in the same place you should have folders called: win32 win32com win32comext and within those there are demos etc. There is also a help file of dubious value to a beginner. The best asource is Mark Hammond's O'Reilly book tho' Activestate probably install it in the same place but I don't know... Alan G ------_=_NextPart_001_01C0D7DA.98E2B2D0 Content-type: text/html; charset="iso-8859-1"
  Ok, maybe I'm just really unco at finding documentation, but this mythical com module for win32...I can't find it for the life of me.  I am planning on controlling internet explorer using it  
 
Assuming you have BeOpen Python 2 and installed winall in the same place you should
have folders called:
 
win32
win32com
win32comext
 
and within those there are demos etc.
 
There is also a help file of dubious value to a beginner. The best asource is
Mark Hammond's O'Reilly book tho'
 
Activestate probably install it in the same place but I don't know...
 
Alan G
 
------_=_NextPart_001_01C0D7DA.98E2B2D0-- From alan.gauld@bt.com Tue May 8 17:23:06 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 8 May 2001 17:23:06 +0100 Subject: [Tutor] selecting specific items from a list Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D74E@mbtlipnt02.btlabs.bt.co.uk> > Let's say I have the following list: > > [(3,3),(2,0),(5,5), (1,1), (4,5), (a,a), (a,e), (b,b), (c,d)] > > How can I tell the computer to return to me only those items > in the list for > which x==y. That is, [(3,3), (5,5), (1,1), (a,a), (b,b)]. Thats exactly what reduce() is for. def sames(t): return t[0] == t[1] # test an element newlist = reduce(sames, juliettelist) #use the test as an argument Take a look at my Functional Programming for an intro to these types of functions: http://www.crosswinds.net/~agauld/tutfctnl.htm Alan G From bdupire@seatech.fau.edu Tue May 8 17:32:20 2001 From: bdupire@seatech.fau.edu (Benoit Dupire) Date: Tue, 08 May 2001 12:32:20 -0400 Subject: [Tutor] selecting specific items from a list References: <5104D4DBC598D211B5FE0000F8FE7EB20751D74E@mbtlipnt02.btlabs.bt.co.uk> Message-ID: <3AF81F94.1765214C@seatech.fau.edu> alan.gauld@bt.com wrote: > > Let's say I have the following list: > > > > [(3,3),(2,0),(5,5), (1,1), (4,5), (a,a), (a,e), (b,b), (c,d)] > > > > How can I tell the computer to return to me only those items > > in the list for > > which x==y. That is, [(3,3), (5,5), (1,1), (a,a), (b,b)]. > > Thats exactly what reduce() is for. you mean filter(), uh? > > > def sames(t): return t[0] == t[1] # test an element > newlist = reduce(sames, juliettelist) #use the test as an argument > > > Take a look at my Functional Programming for an intro to these > types of functions: > > http://www.crosswinds.net/~agauld/tutfctnl.htm > > Alan G > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Benoit Dupire Graduate Student ---------------- I'd like to buy a new Boomerang. How can i get rid of the old one? From python.tutorial@jarava.org Tue May 8 17:34:40 2001 From: python.tutorial@jarava.org (Javier JJ) Date: Tue, 8 May 2001 18:34:40 +0200 Subject: [Tutor] XML-RPC, ActiveState 2.1 and Linux?? Message-ID: <00cf01c0d7dc$cfcb5480$0124a8c0@uno> Hi all!! Been "toying" with Python for a while, and got used to ActiveState "packaging" of it... Now i've installed a copy of Linux under VMWare to do some testing of a c/s app (no second PC, I'm afraid), and I need to use xmlrpc for that. If I remember correctly, the xmlrpclib came with ActiveState 2.0 under windows, but I've intalled the RPMs for both 2.0 and 2.1 under linux, and no xmlrpc present... Am I missing something? Should I just go ahead an grab it from windows? It's not that it's a problem to install, but that I'm worried about another unexpeceted "differences". TIA Javier ---- Portable: survives system reboot. From maritza_rodz@hotmail.com Tue May 8 17:49:03 2001 From: maritza_rodz@hotmail.com (Maritza Rodriguez) Date: Tue, 08 May 2001 11:49:03 -0500 Subject: [Tutor] 15 puzzle Message-ID: I've been working with Glen Barnett on my program for the 15 puzzle. He came up with this program which gives us the 4x4 matrix with the numbers 1-15 in order from left to right and a blank space after the 15. Also, it gives two additional buttons under the matrix, one that reads "SCRAMBLE" and another that reads "DONE". We have not been able to figure out how to move the buttons so that if a button is clicked on (one that is next to the blank space, of course), it will automatically just pop into the blank spot. Does anyone have any suggestions? Maritza from Tkinter import * import sys root = Tk() root.title("15 PUZZLE") frame = Frame(root) frame["height"]=100 frame["width"]=100 frame["borderwidth"]=4 frame["relief"]=RAISED frame.grid(row=0,column=0,sticky=E+W+N+S) frame2 = Frame(root) frame2["height"]=10 frame2["width"]=80 frame2["borderwidth"]=4 frame2["relief"]=RAISED frame2.grid(row=1,column=0,sticky=E+W+N+S) names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"] n=0 for i in range (4): for j in range(4): if n!=15: item=Button(frame,text=names[n]) item.grid(row=i,column=j,sticky=E+W+N+S) n=n+1 quit = Button(root,text="DONE") quit.grid(row=2,column=0,sticky=E+W+N+S) scramble = Button(root,text="SCRAMBLE") scramble.grid(row=3,column=0,sticky=E+W+N+S) root.mainloop() _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From alan.gauld@bt.com Tue May 8 17:50:52 2001 From: alan.gauld@bt.com (alan.gauld@bt.com) Date: Tue, 8 May 2001 17:50:52 +0100 Subject: [Tutor] selecting specific items from a list Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D74F@mbtlipnt02.btlabs.bt.co.uk> > alan.gauld@bt.com wrote: > > Thats exactly what reduce() is for. > > you mean filter(), uh? Blush! Yes I meant filter - I should read my own tutor mebbe :-? [FWIW reduce() combines elements of a list into a single element, filter returns those passing the test function criteria...] Apologies Alan G From cooler12001@yahoo.com Tue May 8 18:21:19 2001 From: cooler12001@yahoo.com (Matthews James) Date: Tue, 8 May 2001 10:21:19 -0700 (PDT) Subject: [Tutor] question about renaming a file Message-ID: <20010508172119.54879.qmail@web11405.mail.yahoo.com> ok i figured out my last question. but i ran into another one that i really can't do anything with MY CODE: #################################################### months = {'01':'JAN.','02':'FEB.','03':'MAR.','04':'APR.','05':'MAY.',\ '06':'JUN.','07':'JUL.','08':'AUG.','09':'SEP.','10':'OCT.',\ '11':'NOV.','12':'DEC.'} def stamp(filename): times = filename time = times[0:2]+'.'+times[2:4] month = times[4:6] day = times[6:8] year = times[9:11] print time, if months.has_key(month): mon = months[month] print months[month], print day, print year #################################################### this is suppose to open a file that is named by the date in which the file was made: 12220508.01 [1222] = 12:12 == time [05] = May == month [08] = Tuesday == day [01] = 2001 == year the program then converts this info to something better like: 12.12 MAY. TUE. 01 Im want to change the other file's name to this Can anyone help? Thanx James __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ From maritza_rodz@hotmail.com Tue May 8 18:55:05 2001 From: maritza_rodz@hotmail.com (Maritza Rodriguez) Date: Tue, 08 May 2001 12:55:05 -0500 Subject: [Tutor] 15 puzzle Message-ID: This is what I have so far. The program now exits the program by pressing the "DONE" button, which is great. But, what I also want that button to do is tell you whether or not you have a solution to the puzzle, just before it exits. Of course, first I have to figure out how to scramble the buttons in order to have an actual game going. Any suggestions? Maritza import sys from Tkinter import * def die(event=0): sys.exit(0) class Puzzle: def __init__(self,w): names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14", "15"," "] n = 0 for i in range(4): for j in range(4): item1=Button(w,text=names[n]) item1.grid(row=i,column=j,sticky=E+W+N+S) item2=Button(w,text=names[n]) item2.grid(row=i,column=j,sticky=E+W+N+S) item3=Button(w,text=names[n]) item3.grid(row=i,column=j,sticky=E+W+N+S) item4=Button(w,text=names[n]) item4.grid(row=i,column=j,sticky=E+W+N+S) item5=Button(w,text=names[n]) item5.grid(row=i,column=j,sticky=E+W+N+S) item6=Button(w,text=names[n]) item6.grid(row=i,column=j,sticky=E+W+N+S) item7=Button(w,text=names[n]) item7.grid(row=i,column=j,sticky=E+W+N+S) item8=Button(w,text=names[n]) item8.grid(row=i,column=j,sticky=E+W+N+S) item9=Button(w,text=names[n]) item9.grid(row=i,column=j,sticky=E+W+N+S) item10=Button(w,text=names[n]) item10.grid(row=i,column=j,sticky=E+W+N+S) item11=Button(w,text=names[n]) item11.grid(row=i,column=j,sticky=E+W+N+S) item12=Button(w,text=names[n]) item12.grid(row=i,column=j,sticky=E+W+N+S) item13=Button(w,text=names[n]) item13.grid(row=i,column=j,sticky=E+W+N+S) item14=Button(w,text=names[n]) item14.grid(row=i,column=j,sticky=E+W+N+S) item15=Button(w,text=names[n]) item15.grid(row=i,column=j,sticky=E+W+N+S) n = n+1 f = Frame(w) b1=Button(f,text="SCRAMBLE") b2=Button(f,text="DONE") if "DONE": b2["command"] = die b1.pack(side=LEFT) b2.pack(side=RIGHT) f.grid(row=4,column=0,columnspan=4) root=Tk() gr=Toplevel(root) gr.title("15-PUZZLE") grc = Puzzle (gr) root.withdraw() root.mainloop() _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From arcege@speakeasy.net Tue May 8 19:13:23 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Tue, 8 May 2001 14:13:23 -0400 (EDT) Subject: [Tutor] Python internals. In-Reply-To: <3AF7FE99.5B4FF279@seatech.fau.edu> from "Benoit Dupire" at May 08, 2001 10:11:38 AM Message-ID: <200105081813.f48IDNi01720@dsl092-074-184.bos1.dsl.speakeasy.net> Benoit Dupire wrote > it's up to me to ask something to the Python gurus out there... > > One of the BIG difference between Python and C++, except for speed, is > that Python is dynamic and C++ static. > > Thus, i can define in Python new functions on the fly and take advantage > of features such as > myString= 'a=19+3' > exec(myString) > > But myString could also be a new function. > > My question is the following: how does Python internally create a new > function dynamically, although it's implemented in C, where such > features are not allowed (static) ? > How are Python functions implemented in C? > My question might have no sense, i know. . . First, remember that everything in Python is translated into bytecode, not directly into C. The byte-code is then evaluated by C routines. So to look at the function, you can disassemble that with the "dis" module. When a function/method/class, etc. gets byte-compiled into a separate "code" object. Python 1.5.2 (#1, Aug 25 2000, 09:33:37) [GCC 2.96 20000731 (experimental)] on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import dis >>> def f(): ... i = 0 ... i = i + 1 ... return i ... >>> f.func_code # the Python "code" object associated with f ", line 1> >>> f.func_code.co_code # this is the byte-code itself '\177\001\000\177\002\000d\001\000}\000\000\177\003\000|\000\000d\002\000\027}\0 00\000\177\004\000|\000\000Sd\000\000S' >>> dis.dis(f.func_code) # now we look at it through the disassembler 0 SET_LINENO 1 3 SET_LINENO 2 6 LOAD_CONST 1 (0) 9 STORE_FAST 0 (i) 12 SET_LINENO 3 15 LOAD_FAST 0 (i) 18 LOAD_CONST 2 (1) 21 BINARY_ADD 22 STORE_FAST 0 (i) 25 SET_LINENO 4 28 LOAD_FAST 0 (i) 31 RETURN_VALUE 32 LOAD_CONST 0 (None) 35 RETURN_VALUE >>> Each of these individual operations (called "opcodes") are then coded in C (or Java for JPython) as cases for a big switch statement (see the function "eval_code2()" in Python/ceval.c). The system uses a traditional operation stack to process the byte code (pushing values on the stack, popping values as you need them and execute the operation). The opcodes deal with data being placed on the stack and things happening so that Python statements look like something intelligent. You can make your own code segments too: >>> g = compile('f()', '', 'exec') >>> g ", line 0> >>> dis.dis(g) 0 SET_LINENO 0 3 SET_LINENO 1 6 LOAD_NAME 0 (f) 9 CALL_FUNCTION 0 12 POP_TOP 13 LOAD_CONST 0 (None) 16 RETURN_VALUE >>> exec g # call 'f()' Most of the time you don't have to worry about all this, but it is cool to know about. You might also want to look into the "parser" and related modules (symbol, token, etc.) which take Python sources and generates byte-code. -Arcege -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From arcege@speakeasy.net Tue May 8 20:58:40 2001 From: arcege@speakeasy.net (Michael P. Reilly) Date: Tue, 8 May 2001 15:58:40 -0400 (EDT) Subject: [Tutor] 15 puzzle In-Reply-To: from "Maritza Rodriguez" at May 08, 2001 12:55:05 PM Message-ID: <200105081958.f48JwfC01793@dsl092-074-184.bos1.dsl.speakeasy.net> Maritza Rodriguez wrote > > This is what I have so far. The program now exits the program by pressing > the "DONE" button, which is great. But, what I also want that button to do > is tell you whether or not you have a solution to the puzzle, just before it > exits. Of course, first I have to figure out how to scramble the buttons in > order to have an actual game going. Any suggestions? > > Maritza > > import sys > from Tkinter import * > > def die(event=0): > sys.exit(0) > > class Puzzle: > def __init__(self,w): > names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14", > "15"," "] > n = 0 > for i in range(4): > for j in range(4): > item1=Button(w,text=names[n]) > item1.grid(row=i,column=j,sticky=E+W+N+S) > > item2=Button(w,text=names[n]) > item2.grid(row=i,column=j,sticky=E+W+N+S) > > item3=Button(w,text=names[n]) > item3.grid(row=i,column=j,sticky=E+W+N+S) > > item4=Button(w,text=names[n]) > item4.grid(row=i,column=j,sticky=E+W+N+S) > > item5=Button(w,text=names[n]) > item5.grid(row=i,column=j,sticky=E+W+N+S) > > item6=Button(w,text=names[n]) > item6.grid(row=i,column=j,sticky=E+W+N+S) > > item7=Button(w,text=names[n]) > item7.grid(row=i,column=j,sticky=E+W+N+S) > > item8=Button(w,text=names[n]) > item8.grid(row=i,column=j,sticky=E+W+N+S) > > item9=Button(w,text=names[n]) > item9.grid(row=i,column=j,sticky=E+W+N+S) > > item10=Button(w,text=names[n]) > item10.grid(row=i,column=j,sticky=E+W+N+S) > > item11=Button(w,text=names[n]) > item11.grid(row=i,column=j,sticky=E+W+N+S) > > item12=Button(w,text=names[n]) > item12.grid(row=i,column=j,sticky=E+W+N+S) > > item13=Button(w,text=names[n]) > item13.grid(row=i,column=j,sticky=E+W+N+S) > > item14=Button(w,text=names[n]) > item14.grid(row=i,column=j,sticky=E+W+N+S) > > item15=Button(w,text=names[n]) > item15.grid(row=i,column=j,sticky=E+W+N+S) > n = n+1 > > > f = Frame(w) > b1=Button(f,text="SCRAMBLE") > b2=Button(f,text="DONE") > if "DONE": > b2["command"] = die > b1.pack(side=LEFT) > b2.pack(side=RIGHT) > f.grid(row=4,column=0,columnspan=4) Add a new method to check the table against the "solution". solution = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", " "] # I would even make 'self.names = self.solution[:]' in __init__ def solved(self): return self.names == self.solution Then make a method to handle the button presses: def is_it_really_solved(self): import Dialog if self.solved: Dialog.Dialog(self, {'title': 'Congratulations', 'text': 'You solved the puzzle!', 'bitmap': Dialog.DIALOG_ICON, 'default': 0, 'strings': ('Ok',)) self.quit() # stop Tkinter else: Dialog.Dialog(self, {'title': 'Sorry', 'text': 'Keep trying', 'bitmap': Dialog.DIALOG_ICON, 'default': 0, 'strings': ('Ok',)) [There are better dialog widgets, but this is one I remember without much reference material right now... and it works] Then for the blocks, you just need to keep track of the buttons, and make commands for them: def makebuttons(self, w): self.buttons = [None] * 16 for i in range(4): for j in range(4): pos = i + j * 4 name = self.names[pos] b = Button(w, text=name, command=lambda self=self, pos=(i, j): self.buttonpress) self.buttons[pos] = b def buttonpress(self, position): (i, j) = pos # find which surrounding button is "blank" and change around # self.names and the text label for the proper buttons in # self.buttons # [Leave this as an exercise for you :)] > > root=Tk() > > > gr=Toplevel(root) > gr.title("15-PUZZLE") > grc = Puzzle (gr) > > > root.withdraw() > root.mainloop() > > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- +----------------------------------+-----------------------------------+ | Michael P. Reilly | arcege@speakeasy.net | From phil.bertram@clear.net.nz Tue May 8 21:50:17 2001 From: phil.bertram@clear.net.nz (Phil Bertram) Date: Wed, 9 May 2001 08:50:17 +1200 Subject: [Tutor] com...? Message-ID: <001a01c0d802$5103c670$b43661cb@pf05nt.bayernz.co.nz> This is a multi-part message in MIME format. ------=_NextPart_000_0012_01C0D865.1262B850 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, A starting point for the I Explorer component object model is here http://msdn.microsoft.com/workshop/browser/overview/overview.asp -----Original Message----- From: Glen Wheeler To: tutor@python.org Date: Wednesday, 9 May 2001 12:17=20 Subject: [Tutor] com...? Hey all, Ok, maybe I'm just really unco at finding documentation, but this = mythical com module for win32...I can't find it for the life of me. I = am planning on controlling internet explorer using it (from within a = python script). A link to some documentation would be nice. Thanks, Glen. ------=_NextPart_000_0012_01C0D865.1262B850 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
 
A starting point for the I Explorer component object = model is=20 here
 
http://msdn.microsoft.com/workshop/browser/overview/overview.asp<= /STRONG>
 
-----Original = Message-----
From:=20 Glen Wheeler <
wheelege@tsn.cc
>
To: =
tutor@python.org <tutor@python.org>
Date: = Wednesday, 9=20 May 2001 12:17
Subject: [Tutor] com...?

  Hey all,
 
  Ok, maybe I'm just really unco at finding documentation, = but this=20 mythical com module for win32...I can't find it for the life of = me.  I am=20 planning on controlling internet explorer using it (from within a = python=20 script).
  A link to some documentation would be nice.
 
  Thanks,
  Glen.
------=_NextPart_000_0012_01C0D865.1262B850-- From maritza_rodz@hotmail.com Tue May 8 22:17:28 2001 From: maritza_rodz@hotmail.com (Maritza Rodriguez) Date: Tue, 08 May 2001 16:17:28 -0500 Subject: [Tutor] 15 puzzle Message-ID: Thank you for responding. I am confused, though. I understand the first part about adding a new method to check the table against the solution. "Solution = ..." : this of,course goes under the class, right? Now we define solved(self); that makes sense. OK when we define is_it_really_solved(self), we are simply saying that if the puzzle is solved it will return the dialog stated and if it is not solved it will return the other dialog stated, right? The next definition is where I got confused. "makebuttons(self,w)"; what is this part of the program saying? What do you mean by blocks and keeping track of the buttons and making commands for them? Are you referring to the number buttons? What does this do to them? Is this the part that moves these buttons? Please excuse me for asking so many questions. I am totally new to programming, especially python. Please help. Maritza >From: "Michael P. Reilly" >Reply-To: arcege@speakeasy.net >To: maritza_rodz@hotmail.com (Maritza Rodriguez) >CC: tutor@python.org >Subject: Re: [Tutor] 15 puzzle >Date: Tue, 8 May 2001 15:58:40 -0400 (EDT) > >Maritza Rodriguez wrote > > > > This is what I have so far. The program now exits the program by >pressing > > the "DONE" button, which is great. But, what I also want that button to >do > > is tell you whether or not you have a solution to the puzzle, just >before it > > exits. Of course, first I have to figure out how to scramble the >buttons in > > order to have an actual game going. Any suggestions? > > > > Maritza > > > > import sys > > from Tkinter import * > > > > def die(event=0): > > sys.exit(0) > > > > class Puzzle: > > def __init__(self,w): > > >names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14", > > "15"," "] > > n = 0 > > for i in range(4): > > for j in range(4): > > item1=Button(w,text=names[n]) > > item1.grid(row=i,column=j,sticky=E+W+N+S) > > > > item2=Button(w,text=names[n]) > > item2.grid(row=i,column=j,sticky=E+W+N+S) > > > > item3=Button(w,text=names[n]) > > item3.grid(row=i,column=j,sticky=E+W+N+S) > > > > item4=Button(w,text=names[n]) > > item4.grid(row=i,column=j,sticky=E+W+N+S) > > > > item5=Button(w,text=names[n]) > > item5.grid(row=i,column=j,sticky=E+W+N+S) > > > > item6=Button(w,text=names[n]) > > item6.grid(row=i,column=j,sticky=E+W+N+S) > > > > item7=Button(w,text=names[n]) > > item7.grid(row=i,column=j,sticky=E+W+N+S) > > > > item8=Button(w,text=names[n]) > > item8.grid(row=i,column=j,sticky=E+W+N+S) > > > > item9=Button(w,text=names[n]) > > item9.grid(row=i,column=j,sticky=E+W+N+S) > > > > item10=Button(w,text=names[n]) > > item10.grid(row=i,column=j,sticky=E+W+N+S) > > > > item11=Button(w,text=names[n]) > > item11.grid(row=i,column=j,sticky=E+W+N+S) > > > > item12=Button(w,text=names[n]) > > item12.grid(row=i,column=j,sticky=E+W+N+S) > > > > item13=Button(w,text=names[n]) > > item13.grid(row=i,column=j,sticky=E+W+N+S) > > > > item14=Button(w,text=names[n]) > > item14.grid(row=i,column=j,sticky=E+W+N+S) > > > > item15=Button(w,text=names[n]) > > item15.grid(row=i,column=j,sticky=E+W+N+S) > > n = n+1 > > > > > > f = Frame(w) > > b1=Button(f,text="SCRAMBLE") > > b2=Button(f,text="DONE") > > if "DONE": > > b2["command"] = die > > b1.pack(side=LEFT) > > b2.pack(side=RIGHT) > > f.grid(row=4,column=0,columnspan=4) > >Add a new method to check the table against the "solution". > > solution = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", > "12", "13", "14", "15", " "] > # I would even make 'self.names = self.solution[:]' in __init__ > > def solved(self): > return self.names == self.solution > >Then make a method to handle the button presses: > def is_it_really_solved(self): > import Dialog > if self.solved: > Dialog.Dialog(self, {'title': 'Congratulations', > 'text': 'You solved the puzzle!', > 'bitmap': Dialog.DIALOG_ICON, > 'default': 0, > 'strings': ('Ok',)) > self.quit() # stop Tkinter > else: > Dialog.Dialog(self, {'title': 'Sorry', > 'text': 'Keep trying', > 'bitmap': Dialog.DIALOG_ICON, > 'default': 0, > 'strings': ('Ok',)) >[There are better dialog widgets, but this is one I remember without much >reference material right now... and it works] > >Then for the blocks, you just need to keep track of the buttons, and >make commands for them: > def makebuttons(self, w): > self.buttons = [None] * 16 > for i in range(4): > for j in range(4): > pos = i + j * 4 > name = self.names[pos] > b = Button(w, text=name, > command=lambda self=self, pos=(i, j): >self.buttonpress) > self.buttons[pos] = b > > def buttonpress(self, position): > (i, j) = pos > # find which surrounding button is "blank" and change around > # self.names and the text label for the proper buttons in > # self.buttons > # [Leave this as an exercise for you :)] > > > > > root=Tk() > > > > > > gr=Toplevel(root) > > gr.title("15-PUZZLE") > > grc = Puzzle (gr) > > > > > > root.withdraw() > > root.mainloop() > > > > > > _________________________________________________________________ > > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > >-- >+----------------------------------+-----------------------------------+ >| Michael P. Reilly | arcege@speakeasy.net | > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From maritza_rodz@hotmail.com Tue May 8 22:18:05 2001 From: maritza_rodz@hotmail.com (Maritza Rodriguez) Date: Tue, 08 May 2001 16:18:05 -0500 Subject: [Tutor] 15 puzzle Message-ID: Thank you for responding. I am confused, though. I understand the first part about adding a new method to check the table against the solution. "Solution = ..." : this of,course goes under the class, right? Now we define solved(self); that makes sense. OK when we define is_it_really_solved(self), we are simply saying that if the puzzle is solved it will return the dialog stated and if it is not solved it will return the other dialog stated, right? The next definition is where I got confused. "makebuttons(self,w)"; what is this part of the program saying? What do you mean by blocks and keeping track of the buttons and making commands for them? Are you referring to the number buttons? What does this do to them? Is this the part that moves these buttons? Please excuse me for asking so many questions. I am totally new to programming, especially python. Please help. Maritza >From: "Michael P. Reilly" >Reply-To: arcege@speakeasy.net >To: maritza_rodz@hotmail.com (Maritza Rodriguez) >CC: tutor@python.org >Subject: Re: [Tutor] 15 puzzle >Date: Tue, 8 May 2001 15:58:40 -0400 (EDT) > >Maritza Rodriguez wrote > > > > This is what I have so far. The program now exits the program by >pressing > > the "DONE" button, which is great. But, what I also want that button to >do > > is tell you whether or not you have a solution to the puzzle, just >before it > > exits. Of course, first I have to figure out how to scramble the >buttons in > > order to have an actual game going. Any suggestions? > > > > Maritza > > > > import sys > > from Tkinter import * > > > > def die(event=0): > > sys.exit(0) > > > > class Puzzle: > > def __init__(self,w): > > >names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14", > > "15"," "] > > n = 0 > > for i in range(4): > > for j in range(4): > > item1=Button(w,text=names[n]) > > item1.grid(row=i,column=j,sticky=E+W+N+S) > > > > item2=Button(w,text=names[n]) > > item2.grid(row=i,column=j,sticky=E+W+N+S) > > > > item3=Button(w,text=names[n]) > > item3.grid(row=i,column=j,sticky=E+W+N+S) > > > > item4=Button(w,text=names[n]) > > item4.grid(row=i,column=j,sticky=E+W+N+S) > > > > item5=Button(w,text=names[n]) > > item5.grid(row=i,column=j,sticky=E+W+N+S) > > > > item6=Button(w,text=names[n]) > > item6.grid(row=i,column=j,sticky=E+W+N+S) > > > > item7=Button(w,text=names[n]) > > item7.grid(row=i,column=j,sticky=E+W+N+S) > > > > item8=Button(w,text=names[n]) > > item8.grid(row=i,column=j,sticky=E+W+N+S) > > > > item9=Button(w,text=names[n]) > > item9.grid(row=i,column=j,sticky=E+W+N+S) > > > > item10=Button(w,text=names[n]) > > item10.grid(row=i,column=j,sticky=E+W+N+S) > > > > item11=Button(w,text=names[n]) > > item11.grid(row=i,column=j,sticky=E+W+N+S) > > > > item12=Button(w,text=names[n]) > > item12.grid(row=i,column=j,sticky=E+W+N+S) > > > > item13=Button(w,text=names[n]) > > item13.grid(row=i,column=j,sticky=E+W+N+S) > > > > item14=Button(w,text=names[n]) > > item14.grid(row=i,column=j,sticky=E+W+N+S) > > > > item15=Button(w,text=names[n]) > > item15.grid(row=i,column=j,sticky=E+W+N+S) > > n = n+1 > > > > > > f = Frame(w) > > b1=Button(f,text="SCRAMBLE") > > b2=Button(f,text="DONE") > > if "DONE": > > b2["command"] = die > > b1.pack(side=LEFT) > > b2.pack(side=RIGHT) > > f.grid(row=4,column=0,columnspan=4) > >Add a new method to check the table against the "solution". > > solution = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", > "12", "13", "14", "15", " "] > # I would even make 'self.names = self.solution[:]' in __init__ > > def solved(self): > return self.names == self.solution > >Then make a method to handle the button presses: > def is_it_really_solved(self): > import Dialog > if self.solved: > Dialog.Dialog(self, {'title': 'Congratulations', > 'text': 'You solved the puzzle!', > 'bitmap': Dialog.DIALOG_ICON, > 'default': 0, > 'strings': ('Ok',)) > self.quit() # stop Tkinter > else: > Dialog.Dialog(self, {'title': 'Sorry', > 'text': 'Keep trying', > 'bitmap': Dialog.DIALOG_ICON, > 'default': 0, > 'strings': ('Ok',)) >[There are better dialog widgets, but this is one I remember without much >reference material right now... and it works] > >Then for the blocks, you just need to keep track of the buttons, and >make commands for them: > def makebuttons(self, w): > self.buttons = [None] * 16 > for i in range(4): > for j in range(4): > pos = i + j * 4 > name = self.names[pos] > b = Button(w, text=name, > command=lambda self=self, pos=(i, j): >self.buttonpress) > self.buttons[pos] = b > > def buttonpress(self, position): > (i, j) = pos > # find which surrounding button is "blank" and change around > # self.names and the text label for the proper buttons in > # self.buttons > # [Leave this as an exercise for you :)] > > > > > root=Tk() > > > > > > gr=Toplevel(root) > > gr.title("15-PUZZLE") > > grc = Puzzle (gr) > > > > > > root.withdraw() > > root.mainloop() > > > > > > _________________________________________________________________ > > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > >-- >+----------------------------------+-----------------------------------+ >| Michael P. Reilly | arcege@speakeasy.net | > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com From cooler12001@yahoo.com Tue May 8 23:37:32 2001 From: cooler12001@yahoo.com (Matthews James) Date: Tue, 8 May 2001 15:37:32 -0700 (PDT) Subject: [Tutor] having trouble with files!!!please help Message-ID: <20010508223732.25086.qmail@web11407.mail.yahoo.com> I am haveing some trouble with trying toget every file that end's with .01w and then renaming them accordingly. example 16460508.01w which means 16:46 for the time may for the month 08 for the day 01 for the year i have these things all in one folder, and i have wrote a program that lets me rename them like so for the example above [16:46][MAY][08][01] but the problem is that i'm want to not have to type them in but, just tell the program what folder they are in, then it will do the rest here is the code ##################################################### import os months = {'01':'[JAN]','02':'[FEB]','03':'[MAR]','04':'[APR]','05':'[MAY]',\ '06':'[JUN]','07':'[JUL]','08':'[AUG]','09':'[SEP]','10':'[OCT]',\ '11':'[NOV]','12':'[DEC]'} def mk_keylog(filename): '''(filename)-=> name of the keylog! file This Function will rename and move the keylog! files to a closer temp folder''' times = filename time = '['+times[0:2]+'.'+times[2:4]+']' month = times[4:6] day = '['+times[6:8]+']' year = '['+times[9:11]+']' mon = months[month] print time, print months[month], print day, print year if not os.path.isdir('C:\\TEMP\\sys.admir'): os.mkdir('C:\\TEMP\\sys.admir') os.rename('C:\\WINDOWS\\TEMP\\'+filename,'C:\\TEMP\\sys.admir\\'+time+mon+day+year) print '-'*40 print ' '*13,'keylog!Partner',' '*13 print '-'*40 print print print filename=raw_input('File Name:') mk_keylog(filename) ##################################################### thank you James __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ From maritza_rodz@hotmail.com Tue May 8 23:48:56 2001 From: maritza_rodz@hotmail.com (Maritza Rodriguez) Date: Tue, 08 May 2001 17:48:56 -0500 Subject: [Tutor] 15 puzzle Message-ID: Here is what I have for my "15 Puzzle" program. The "EXIT" button quits the game completely. The "DONE" button prints the messages that I want (although I don't know if it will work once I figure out how to Scramble and play the game). I tried to add a definition for "Scramble", but it is not working. Can anyone help me figure out if I am close or just totally way off? Also, I just cannot figure out how to move the buttons to the blank spot. Maritza #Sets up the matrix and "DONE", "SCRAMBLE" and "EXIT" buttons #Quits with "EXIT" button #DONE button prints "solution" or "nosolution" import sys from Tkinter import * import string import copy import whrandom #import msvcrt #import array #from Numeric import* def die(event=0): sys.exit(0) def solution(f): print "Great! You found a solution!!" def nosolution(f): print "Sorry! No Solution!!" names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14", "15"," "] blankrow=3 blankcol=3 def Scramble(f): pass acpy = list(names) for x in range(1,16): sizeofacpy = len(acpy)-1 location = whrandom.randint(0,sizeofacpy) names[x] = acpy[location] del acpy[location] offs = names.index(" ") blankrow=offs/4 blankcol=offs%4 def __init__(self,w): n = 0 for i in range(4): for j in range(4): item1=Button(w,text=names[n]) item1.grid(row=i,column=j,sticky=E+W+N+S) item2=Button(w,text=names[n]) item2.grid(row=i,column=j,sticky=E+W+N+S) item3=Button(w,text=names[n]) item3.grid(row=i,column=j,sticky=E+W+N+S) item4=Button(w,text=names[n]) item4.grid(row=i,column=j,sticky=E+W+N+S) item5=Button(w,text=names[n]) item5.grid(row=i,column=j,sticky=E+W+N+S) item6=Button(w,text=names[n]) item6.grid(row=i,column=j,sticky=E+W+N+S) item7=Button(w,text=names[n]) item7.grid(row=i,column=j,sticky=E+W+N+S) item8=Button(w,text=names[n]) item8.grid(row=i,column=j,sticky=E+W+N+S) item9=Button(w,text=names[n]) item9.grid(row=i,column=j,sticky=E+W+N+S) item10=Button(w,text=names[n]) item10.grid(row=i,column=j,sticky=E+W+N+S) item11=Button(w,text=names[n]) item11.grid(row=i,column=j,sticky=E+W+N+S) item12=Button(w,text=names[n]) item12.grid(row=i,column=j,sticky=E+W+N+S) item13=Button(w,text=names[n]) item13.grid(row=i,column=j,sticky=E+W+N+S) item14=Button(w,text=names[n]) item14.grid(row=i,column=j,sticky=E+W+N+S) item15=Button(w,text=names[n]) item15.grid(row=i,column=j,sticky=E+W+N+S) n = n+1 f = Frame(w) b1=Button(f,text="SCRAMBLE") b1.bind("