Re: [Tutor] critique my script: add columns in a file

2007-02-14 Thread Alan Gauld
Christopher Spears [EMAIL PROTECTED] wrote I modified a script I found in Programming Python I assume it was the first edition of Programming Python? #!/usr/bin/python import string def find_longest_line(fileName): longest_col = [] for lines_in_file in open(fileName, 'r').readlines():

Re: [Tutor] critique my script: add columns in a file

2007-02-14 Thread Kent Johnson
Christopher Spears wrote: I created a file called table.txt. Here is the file's contents: 1 5 10 2 1.0 2 10 20 4 2.0 3 3 15 30 8 3 2 1 4 20 40 16 4.0 I modified a script I found in

[Tutor] critique my script: add columns in a file

2007-02-13 Thread Christopher Spears
I created a file called table.txt. Here is the file's contents: 1 5 10 2 1.0 2 10 20 4 2.0 3 3 15 30 8 3 2 1 4 20 40 16 4.0 I modified a script I found in Programming Python and created

Re: [Tutor] critique my script!

2006-08-03 Thread Alan Gauld
I created a function that takes a pattern and a base path and then uses os.walk and glob to traverse directories starting from the base path and place files that match the glob pattern in a dictionary. I'm not sure why you are traversing the paths a second time. Why not just apply glob within

Re: [Tutor] critique my script!

2006-08-03 Thread Kent Johnson
Alan Gauld wrote: I created a function that takes a pattern and a base path and then uses os.walk and glob to traverse directories starting from the base path and place files that match the glob pattern in a dictionary. I'm not sure why you are traversing the paths a second time. Why

Re: [Tutor] critique my script!

2006-08-03 Thread Christopher Spears
I didn't know I could place the glob in the os.walk traversal. Could you give me an example of how to do this? --- Alan Gauld [EMAIL PROTECTED] wrote: I created a function that takes a pattern and a base path and then uses os.walk and glob to traverse directories starting from the base

Re: [Tutor] critique my script!

2006-08-03 Thread Alan Gauld
I didn't know I could place the glob in the os.walk traversal. Could you give me an example of how to do this? I'm not sure why you see a problem. A simplified form of your code is like this: for root,dirs,files in os.walk(abs_base): for name in dirs: path = os.path.join(root,

Re: [Tutor] critique my script!

2006-08-03 Thread Christopher Spears
I rewrote my code with Alan's suggestions in mind. #!/usr/bin/python import os, os.path, glob def glob_files(pattern, base_path = '.'): abs_base = os.path.abspath(base_path) #path_list = [] #path_list.append(abs_base) globbed_dict = {} cwd = os.getcwd()

Re: [Tutor] critique my script!

2006-08-03 Thread Alan Gauld
Under the LearningToProgram directory is a test directory that doesn't contain any .pyc files, so the script's returned value is correct. However, .pyc files exist in the LearningToProgram directory, and I would like to put those files in the dictionary too. Is there an elegant way to

Re: [Tutor] critique my script!

2006-08-03 Thread Python
(Sorry about accidental posting before I had finished editing.) On Thu, 2006-08-03 at 15:37 -0700, Christopher Spears wrote: I rewrote my code with Alan's suggestions in mind. #!/usr/bin/python import os, os.path, glob def glob_files(pattern, base_path = '.'): abs_base =

Re: [Tutor] critique my script!

2006-08-03 Thread Python
On Thu, 2006-08-03 at 15:37 -0700, Christopher Spears wrote: I rewrote my code with Alan's suggestions in mind. #!/usr/bin/python import os, os.path, glob def glob_files(pattern, base_path = '.'): abs_base = os.path.abspath(base_path) #path_list = []

Re: [Tutor] critique my script!

2006-08-03 Thread Python
On Fri, 2006-08-04 at 00:26 +0100, Alan Gauld wrote: Under the LearningToProgram directory is a test directory that doesn't contain any .pyc files, so the script's returned value is correct. However, .pyc files exist in the LearningToProgram directory, and I would like to put those

Re: [Tutor] critique my script!

2006-08-03 Thread Kent Johnson
Christopher Spears wrote: I rewrote my code with Alan's suggestions in mind. #!/usr/bin/python import os, os.path, glob def glob_files(pattern, base_path = '.'): abs_base = os.path.abspath(base_path) #path_list = [] #path_list.append(abs_base) globbed_dict = {}

[Tutor] critique my script again!

2006-08-03 Thread Christopher Spears
Here is the complete script with documentation: #!/usr/bin/python #This script prompts the user for a path and a glob pattern. #The script firsts looks in the directory denoted by the path #for a matching file. If a match is found, the path and file are added #to a dictionary as a key and

[Tutor] critique my script!

2006-08-02 Thread Christopher Spears
I created a function that takes a pattern and a base path and then uses os.walk and glob to traverse directories starting from the base path and place files that match the glob pattern in a dictionary. #!/usr/bin/python import os, os.path, glob def glob_files(pattern, base = '.'):

Re: [Tutor] critique my script!

2006-06-24 Thread Alan Gauld
I can't really comment on the GTk bits because I've never used it. From what I can see it looks like a fairly standard type of GUI framework however. A couple of comments: class Conversion_GUI: def print_celsius(self, widget): print Degrees Celsius: %.2f % self.degC I assume this

Re: [Tutor] critique my script!

2006-06-21 Thread Kent Johnson
Christopher Spears wrote: I can apparently call the functions sometimes without (). Why is that? There is an important difference between f and f() - f is a reference to the function object itself, while f() is a *call* of the function. (Call is actually an operator, written (). You can

[Tutor] critique my script!

2006-06-20 Thread Christopher Spears
Here is a little gui I created: #!/usr/bin/python import os, pygtk pygtk.require('2.0') import gtk class GetCwd: def getcwd(self, widget, data=None): print os.getcwd() def delete_event(self, widget, event, data=None):

Re: [Tutor] critique my script!

2006-06-20 Thread Danny Yoo
On Tue, 20 Jun 2006, Christopher Spears wrote: Here is a little gui I created: [gui code cut] Hi Christopher, Looks ok so far. One approach that has a lot of popularity behind it is called the model-view-controller approach. The idea is that we should be able to build up the graphical

Re: [Tutor] critique my script!

2006-06-20 Thread Danny Yoo
doesn't do_nothing(), but does something more interesting, something like: # view = View() view.on_button_pressed = os.getcwd # Gaaa. Quick revision: ## def print_cwd():

Re: [Tutor] critique my script!

2006-06-20 Thread Christopher Spears
I made the changes that Danny suggested to my script: #!/usr/bin/python import os, pygtk pygtk.require('2.0') import gtk class View: def delete_event(self, widget, event, data=None): gtk.main_quit() return False def