<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4937.800" name=GENERATOR></HEAD>
<BODY>
<P><FONT size=2>Alan and Roger!<BR>I actually found a way to write the file to
the other file perfectly. It is not taking out the <cr> but that is
OK for right now. It is just something more to work on. At least it
is not deleting it all the way! Big Step! Here is what I
have:</FONT></P>
<P><FONT size=2><BR><FONT color=#ff0000><FONT color=#0000ff>import os<BR>import
Tkinter<BR>import sys<BR>import dialog<BR><BR>root=Tkinter.Tk()<BR>result =
0<BR>def doDialog():<BR> global result<BR> result =
dialog.dialog()<BR><BR>f=Tkinter.Button(root, text="Find Files",
command=doDialog)<BR>f.pack()<BR>x=Tkinter.Button(root, text="Close",
command=sys.exit)<BR>x.pack()<BR><BR>if f:<BR>
fileName=dialog.dialog()<BR> in_file =
open(fileName,'r').readlines()<BR> out_file = open(fileName +
'_cleaned', 'w')<BR> for i in in_file: <FONT color=#ff0000>#Changed
the for statement to say in_file (duh!)</FONT><BR>
out_file.write(i[:-1] + '\n') <FONT color=#ff0000>#maybe the problem is
here?<BR></FONT> print 'File cleaned'<BR>
in_file.close()<BR> out_file.close()<BR> print
filename<BR><BR><BR> <BR>root.mainloop()<BR></FONT><BR></FONT>-----Original
Message-----<BR>From: Alan Gauld [<A
href="mailto:alan.gauld@blueyonder.co.uk">mailto:alan.gauld@blueyonder.co.uk</A>]<BR>Sent:
Friday, April 16, 2004 2:17 PM<BR>To: David Talaga; Roger Merchberger;
tutor@python.org<BR>Subject: Re: [Tutor] deleting CR within
files<BR><BR><BR>> root=Tkinter.Tk()<BR>> f=Tkinter.Button(root,
text="Find Files",<BR>command=dialog.dialog).pack()<BR>>
x=Tkinter.Button(root, text="Close", command=sys.exit).pack()<BR><BR>Like
another recent poster you are assigning the value of pack()<BR>to the variables.
But pack returns None. In this case you don't<BR>use f or x so it doesn't matter
but could lead to some strange<BR>things if you tried to use them
later...<BR><BR>> if f:<BR><BR>Oops, sorry, you do use f, it will be false
since pack() returns<BR>none wich is considered as false.<BR><BR>As a result the
block of code inside the if never gets executed.<BR><BR>You need to define the
widget then pack it:<BR><BR>f=Tkinter.Button(root, text="Find Files",
command=dialog.dialog)<BR>f.pack()<BR><BR>The other problem is that oits not
clear how you rtrieve the<BR>output from dialog.dialog. I suspect you need to
wrap that in<BR>a local function that stores the value for you:<BR><BR>result =
0<BR>def doDialog()<BR> global result<BR> result =
dialog.dialog()<BR><BR>Now pass doDialog into the command parameter and when
the<BR>button is pressed the result will be stored in the global<BR>variable
result. [ If you were using objects you would make<BR>the doDialog a method and
store the result in an attribute<BR>of the class to avoid using a global
variable...]<BR><BR>HTH,<BR><BR>Alan G<BR>Author of the Learn to Program web
tutor<BR><A target=_blank
href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</A><BR></P></FONT></BODY></HTML>