Re: [Tutor] SPE - Stani's Python Editor ?
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Hengge Sent: Tuesday, January 02, 2007 4:57 PM To: Dick Moores Cc: tutor@python.org Subject: Re: [Tutor] SPE - Stani's Python Editor ? I've recently started playing with Eclipse and the two PyDev plugin's over the holidays. I'm seriously liking it... but my likes are more closely related to Visual Studio as an editor, so this is like the perfect environment for me.. http://www.showmedo.com/videos/series?name=PyDevEclipseList This link shows you two video's on how pydev works, and how to setup. I played with Eclipse a little bit. I got annoyed that the plugins would nickel and dime you to death. Pydev is free, but the additional features in Pydev Extensions cost $. I heard there was a plugin for vi emulation. Unfortunately, it was another plugin that you had to pay for. I decided to stick with VIM where the plugins are free. I recently starting using VIM's snippets.emu plugin. It emulates TextMate's snippets. TextMate is an editor for OS X that is getting a lot of attention. There are people working on TextMate-like editors for Windows and Linux. Mike - NOTICE: This e-mail transmission and any documents or files attached to it contain information for the sole use of the above-identified individual or entity. Its contents may be privileged, confidential, and exempt from disclosure under the law. Any dissemination, distribution, or copying of this communication is strictly prohibited. Please notify the sender immediately if you are not the intended recipient. FGNS ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 35, Issue 8
Take a look at Movable Python. It may not be exactly what you're looking for, but it may turn out to be a resource to leverage from. Message: 1 Date: Tue, 2 Jan 2007 21:14:16 -0500 From: Daniel McQuay [EMAIL PROTECTED] Subject: Re: [Tutor] Starting python from a DOS prompt from any directory? Nope, he said it was a networked PC but that Python was in his D: drive, which I assumed was local. But that raises an interesting proposition,. one that I've never tried. Is it possible under Windows to install Python from machine A onto a network drive and then run Python from machine B accessing that drive? In other words does the installer need to do any magic in the registry for Python to work or is it all just path setting and shortcuts? Can anyone confirm or otherwise the possibility? i can try this under my networked drive tomorrow at school and if in fact you can. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with rewriting script to use Decimal module
At 10:39 AM 1/2/2007, Kent Johnson wrote: Dick Moores wrote: from decimal import Decimal as D def bestFracForMinimumError(decimal, minimumError): denom = 0 while True: denom += 1 num = round(D(str(decimal)) * D(str(denom))) error = abs(str((str(D(num) / D(str(denom))) - This looks backwards^^ Thanks for catching that. Don't you need D(str(num)) ? Then converting it back to a str before you call abs will not work. Your old approach of def D(num): return Decimal(str(num)) would probably make for more readable code and fewer errors. Yes, I went back to it. I'm not sure this approach will work, though, if you are trying to get higher precision, I would think you would have to do all the calculations in Decimal, not going to floats for num. I admit I haven't thought it through, though. I think you can use Decimal.quantize() instead of round(). Thanks very much, Kent. You got me back on track. Dick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SPE - Stani's Python Editor ?
Pydev Extensions are only about $40. Most of the plugin's are $50 or less if not free... I'd personally much rather pay for the feature's I want, as I want them, then be forced bloated software (Visual Studio) that will cost hundreds to thousands of dollars, which will still require very expensive add-ons, as well as forces you to live in the MS Languages (Which is fine if you need that) I guess I don't see a problem with helping out active projects, I normally toss open source software that I use for any amount of time atleast one tip. In the end, its still a ton cheaper then Visual Studio or some of the other options out there. On 1/3/07, Mike Hansen [EMAIL PROTECTED] wrote: -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Hengge Sent: Tuesday, January 02, 2007 4:57 PM To: Dick Moores Cc: tutor@python.org Subject: Re: [Tutor] SPE - Stani's Python Editor ? I've recently started playing with Eclipse and the two PyDev plugin's over the holidays. I'm seriously liking it... but my likes are more closely related to Visual Studio as an editor, so this is like the perfect environment for me.. http://www.showmedo.com/videos/series?name=PyDevEclipseList This link shows you two video's on how pydev works, and how to setup. I played with Eclipse a little bit. I got annoyed that the plugins would nickel and dime you to death. Pydev is free, but the additional features in Pydev Extensions cost $. I heard there was a plugin for vi emulation. Unfortunately, it was another plugin that you had to pay for. I decided to stick with VIM where the plugins are free. I recently starting using VIM's snippets.emu plugin. It emulates TextMate's snippets. TextMate is an editor for OS X that is getting a lot of attention. There are people working on TextMate-like editors for Windows and Linux. Mike - NOTICE: This e-mail transmission and any documents or files attached to it contain information for the sole use of the above-identified individual or entity. Its contents may be privileged, confidential, and exempt from disclosure under the law. Any dissemination, distribution, or copying of this communication is strictly prohibited. Please notify the sender immediately if you are not the intended recipient. FGNS ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with rewriting script to use Decimal module
On Wed, 3 Jan 2007, Dick Moores wrote: At 01:17 PM 1/2/2007, Terry Carroll wrote: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52317 Terry, that is truly ingenious. Is there an explication anywhere of exactly how it works? There is in the printed copy of the Python Cookbook. I happened to have read it last week, which is the only reason I knew about it. I don't have the book handy, but here's what I remember of it. It's based on the concept of the Farey sequence of fractions. I may explain it imperfectly, but it's basically the sequence of fractions with integer denominators and numerators, each reduced to the lowest common denominator, and then arranged in numerically ascending order. The sequence has an order N, where N is the highest integer used in the denominator. It's easier to show an example. Here's the Farey sequence for order 4; I'll include a decimal approximation to show the basis for the ordering: 0/1, 1/4, 1/3, 1/2, 2/3, 3/4, 1/1 0.00.25 0.33 0.500.67 0.75 1.00 It's been observed (by a guy named Farey, hence the name) that, for any subsequence of three consecutive fractions in the sequence, if expressed as A/B, C/D, E/F; then C/D = (A+E)/(B+F). For example, in the above seqence, take the three-fraction subsequence {1/2, 2/3, 3/4}. In this, A=1, B=2, C=2, D=3, E=3, F=4, so: (A+E)/(B+F) = (1+3)/(2+4) = 4/6 = 2/3 = C/D. The inner fraction (C/D) is called the mediant. If I understand the Python algorithm correctly, it takes advantage of this process by essentially constructing a Farey sequence of order 1 (which is essentially {0/1, 1/1}, or {0, 1}), and then calculating the mediant between those two points, thereby constructing a subsequence of order 2; then another mediant between that mediant and one of its neighbors (which neighbor is chose by considering whether the decimal fraction you seek to approximate is greater than or less than the mediant), and then doing this continuously, calculating subsquences of orders 3, 4, etc, until it reaches the desired precision. I just checked, and (big surprise) Wikipedia has an article on the Farey sequence: http://en.wikipedia.org/wiki/Farey_number There's apparently more to it than I described above. They give the same formula I use, but where I use A, B, C, D, E, F, they use A, B, P, Q, C, D, respectively. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with rewriting script to use Decimal module
Dick, if your goal is to have a routine to get the fraction with the least possible error (as opposed to learing how to use Decimal), have a look at this recipe from the Python Cookbook: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52317 Terry, that is truly ingenious. Is there an explication anywhere of exactly how it works? Hi Dick, On a first glance, it looks like it's doing a binary search on the Farey series on some order. (Actually, it's not, but we'll get to that later in this post.) Farey sequences have an entry on Wikipedia: http://en.wikipedia.org/wiki/Farey_number Look at the terms of F_8, for example. If you take two points with some other point between them, say 1/5 and 2/7, notice that: 1 3 2 --- - 5 12 7 If we just do the funny thing by adding the numerators and denominators --- by taking the mediant --- we end up with another term in the Farey sequence. This is very cute. Wait. Actually, what the algorithm is doing doesn't appear to be searching through a particular Farey sequence of order n. Instead, what it's doing is much simpler: it appears to be just taking advanatage of the in-betweenness property of mediants. http://en.wikipedia.org/wiki/Mediant_%28mathematics%29 Oh well, that still works. The algorithm seems to be misnamed, though: I think it should really be described as inexact to rational via mediant approximation. The trick that the algorithm is really a binary-search, using the definition of mediant to find midpoints. Whenever we see something like: while we haven't found the answer: We know that the answer's somewhere between the lower and upper bounds. (precondition) midpoint = some calculation combining the lower and upper bounds if the midpoint is too big: move the upper bound elif the midpoint is too small: move the lower bound else we've found the answer At the end of this, we guarantee our answer's still between the lower and upper bounds. (postcondition) then we should suspect a binary search. In the case of the algorithm in the Cookbook, we can see that it follows this structure very closely. Concretely, when they say: if v * mediant[1] mediant[0]: ... we can do simple equational reasoning to see that this is really saying: if v (mediant[0] / mediant[1]): ... aka: if the value we're looking for is bigger than the mediant, move the lower bound up. The mediant is being represented by a 2-tuple (numerator, denominator), so with that, you should be able to read the case analysis off more easily. Best of wishes! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python class at Foothill College
If you would like to learn Python, Foothill College is offering a course starting Wed. evening, 10 January, at the Middlefield campus on the corner of San Antonio and Middlefield Road in south Palo Alto. The course is designed for students who are already familiar with some type of programming. Here is the course description: CIS 68K INTRODUCTION TO PYTHON PROGRAMMING 5 Units This course will introduce students to the Python language and environment. Python is a portable, interpreted, object-oriented programming language that is often compared to Perl, Java, Scheme and Tcl. The language has an elegant syntax, dynamic typing, and a small number of powerful, high-level data types. It also has modules, classes, and exceptions. Meets Wednesday evenings, 6:00 - 9:40, 10 January - 28 March. If you would like to sign up for the class, please register beforehand by going to: http://www.foothill.fhda.edu/reg/index.php If you have questions, you can contact the instructor at: [EMAIL PROTECTED] __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how do i access object
Ketan Maheshwari [EMAIL PROTECTED] wrote of this class created using a constructor. The constructor essentially creates the circles and the update mathod makes them move randomly. However, at each updation, I want to access each circle to know its coordinates. At the moment I am not able to do that. The circles are stored in a list called items. You can iterate over the items printing out their centres: for circ in items: print circ.getCentres() Where getCentres is a mrethod you will need to write and add to Circle! :-) class Circle: def __init__(self, canvas, xy, ink, delta): def __call__(self): def move(self): root = Tk() ... canvas = Canvas(frame, width=200, height=200, bd=0, highlightthickness=0) canvas.pack() items = [ Circle(canvas, (60, 70), blue, 1), Circle(canvas, (100, 120), green, 1), ] ... for i in range(len(items)): items[i] = items[i]() As is done here except it would be prettier done as for i in items: HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how do i access object
Ketan Maheshwari wrote: Hi All I have this code from the web that I modified according to y requirements. It has a class called Circle. Then there are a few objects of this class created using a constructor. The constructor essentially creates the circles and the update mathod makes them move randomly. However, at each updation, I want to access each circle to know its coordinates. At the moment I am not able to do that. I am sure it should be easy to do. Could anyone help me please. The line xy = self.canvas.coords(self.id) reads the bounding box of the circle. The returned value is a list containing the coordinates of the bounding box of the circle (x0, y0, x1, y1) - in other words the coordinates of the left, top, right and bottom of the circle. This might help a bit: http://infohost.nmt.edu/tcc/help/pubs/tkinter/canvas-concepts.html Kent Thanks, k. Code follows: **code starts here*** from Tkinter import * import time import random class Circle: def __init__(self, canvas, xy, ink, delta): self.canvas = canvas self.id = self.canvas.create_oval( -15, -15, 15, 15, fill=ink ) self.canvas.move(self.id, xy[0], xy[1]) self.delta = delta self.start = self.move def __call__(self): return self.start # get things going def move(self): rand=random.randint(1,4) if rand==1: xy = self.canvas.coords(self.id) #print xy if xy[2] = self.canvas.winfo_width(): self.canvas.move(self.id,-self.delta,0) self.canvas.move(self.id,self.delta,0) elif rand==2: xy = self.canvas.coords(self.id) if xy[0] = 0: self.canvas.move(self.id,self.delta,0) self.canvas.move(self.id,-self.delta,0) elif rand==3: xy = self.canvas.coords(self.id) if xy[1] = 0: self.canvas.move(self.id,0,self.delta) self.canvas.move(self.id,0,-self.delta) else: xy = self.canvas.coords(self.id) if xy[3] = self.canvas.winfo_height(): self.canvas.move(self.id,0,-self.delta) self.canvas.move(self.id,0,self.delta) return self.move root = Tk() root.title(Circles) root.resizable(0, 0) frame = Frame(root, bd=5, relief=SUNKEN) frame.pack() canvas = Canvas(frame, width=200, height=200, bd=0, highlightthickness=0) canvas.pack() items = [ Circle(canvas, (60, 70), blue, 1), Circle(canvas, (100, 120), green, 1), ] root.update() # fix geometry # loop over items try: while 1: for i in range(len(items)): items[i] = items[i]() root.update_idletasks() # redraw root.update() # process events time.sleep(0.02) except TclError: pass # to avoid errors when the window is closed *code ends here** ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Embedding strings in a python script
I have a number of text files which need to be checked into CVS. Each file needs a special text header/footer in order that CVS can track changes and version numbers. Python to the rescue. I've written a small python program which will write the header/footer to all files in the current directory. In order to do this, I need to add this string in my python program. cvs_header=''' ### # # $Header:$ # # $Revision:$ # $Author:$ # $Date:$ # ''' It works just fine. However, the program which I wrote also needs to be kept under version control. When I make changes to that program, I noticed that the header above gets modified by cvs, because it contains key variables which are recognized by cvs. This is unacceptable. So I took this string out of my program, wrote it to a pickle file, and now the pickle file is read at runtime, and the program will write the empty header to the target files. I can check the pickle files into cvs as binary files, and the header strings will not be modified. I now have 3 pickle files I need to distribute with the program, which is a minor nuisance. Even using py2exe on Windows, these 3 files cannot be embedded within the exe itself. What I'd like to know, is there a way I can embed/endcode the cvs string above in the python script, so that when that script is modified and checked into cvs, that the cvs header string above will not be modified by cvs? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Embedding strings in a python script
On 04/01/07, Tony Cappellini [EMAIL PROTECTED] wrote: What I'd like to know, is there a way I can embed/endcode the cvs string above in the python script, so that when that script is modified and checked into cvs, that the cvs header string above will not be modified by cvs? What about this: cvs_header=''' ### # # @Header:@ # # @Revision:@ # @Author:@ # @Date:@ # '''.replace('@', '$') ? -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] how to know if a file exists
hello there, i am writing an app for linux. what command would be easiest to test and see if a certain file exist ? i was going to do something like this try: file = open('/path/to/file', 'rb') return True except: return False but i thought that there would be an easier way. thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to know if a file exists
shawn bright wrote: hello there, i am writing an app for linux. what command would be easiest to test and see if a certain file exist ? i was going to do something like this try: file = open('/path/to/file', 'rb') return True except: return False You should except IOError here, just to be clear and such. but i thought that there would be an easier way. The os module has some function for checking if files exist, I think. Or you could do if targetfile not in os.listdir(directory): return False else: return True But your original solution is okay. HTH, -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to know if a file exists
On 1/4/07, Luke Paireepinart [EMAIL PROTECTED] wrote: shawn bright wrote: hello there, i am writing an app for linux. what command would be easiest to test and see if a certain file exist ? i was going to do something like this try: file = open('/path/to/file', 'rb') return True except: return False You should except IOError here, just to be clear and such. but i thought that there would be an easier way. The os module has some function for checking if files exist, I think. Yes, check out access(): http://docs.python.org/lib/os-file-dir.html André Or you could do if targetfile not in os.listdir(directory): return False else: return True But your original solution is okay. HTH, -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to know if a file exists
thanks, luke, Andre. appreciate it a lot shawn On 1/3/07, Andre Roberge [EMAIL PROTECTED] wrote: On 1/4/07, Luke Paireepinart [EMAIL PROTECTED] wrote: shawn bright wrote: hello there, i am writing an app for linux. what command would be easiest to test and see if a certain file exist ? i was going to do something like this try: file = open('/path/to/file', 'rb') return True except: return False You should except IOError here, just to be clear and such. but i thought that there would be an easier way. The os module has some function for checking if files exist, I think. Yes, check out access(): http://docs.python.org/lib/os-file-dir.html André Or you could do if targetfile not in os.listdir(directory): return False else: return True But your original solution is okay. HTH, -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to know if a file exists
On Thu, 4 Jan 2007, Andre Roberge wrote: i am writing an app for linux. what command would be easiest to test and see if a certain file exist ? i was going to do something like this try: file = open('/path/to/file', 'rb') return True except: return False You should except IOError here, just to be clear and such. but i thought that there would be an easier way. The os module has some function for checking if files exist, I think. Yes, check out access(): http://docs.python.org/lib/os-file-dir.html Hi Andrey, os.path.exists() may also be useful here: http://www.python.org/doc/lib/module-os.path.html#l2h-2163 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with rewriting script to use Decimal module
At 01:17 PM 1/2/2007, Terry Carroll wrote: On Mon, 1 Jan 2007, Dick Moores wrote: bestFracForMinimumError() is only a small part of a program I wrote long ago, called frac.py Dick, if your goal is to have a routine to get the fraction with the least possible error (as opposed to learing how to use Decimal), have a look at this recipe from the Python Cookbook: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52317 Terry, I just noticed that farey(0.36, 10) returns (1, 3), a pretty big miss, IMO. The correct fraction with smallest error and maximum denominator of 10 is 3/8, which I'm proud to say my klunky frac.py (http://www.rcblue.com/Python/fracForWeb.py) produces. Be that as it may, farey() is an amazing program. I appreciate the fast replies from you and Danny to my plea for explication. I'm still working through them. Dick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor