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 fo
"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').rea
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 scri
Christopher Spears wrote:
> import os, os.path, glob
>
> def create_dict(path, globbed_dict):
> os.chdir(path)
> matched_files = glob.glob(pattern)
> if matched_files != []:
> globbed_dict[path] = matched_files
> return globbed_dict
>
As written create_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 value.
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_d
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 t
On Thu, 2006-08-03 at 15:37 -0700, Christopher Spears wrote:
(in the os.walk processing)
> os.chdir(path)
> matched_files = glob.glob(pattern)
>From the os.walk documentation
Note: If you pass a relative pathname, don't change the current working
dir
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 = []
> #path_l
(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 = o
> 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
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()
>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, na
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
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
>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 with
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 = '.'):
path_l
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
I wrote a script that creates a gui using pygtk. The
gui consists of a vertical scrollbar and two buttons.
The user picks a number (degrees Fahrenheit) with the
scrollbar and then clicks the convert button. A
functions converts the number to its equivalent in
degrees Celsius and prints a respons
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 wri
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 button
> 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():
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
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):
gtk.main_qu
24 matches
Mail list logo