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():
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
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
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
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
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
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,
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()
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
(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 =
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 = []
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
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 = {}
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
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 = '.'):
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
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
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):
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
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():
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
21 matches
Mail list logo