FW: [Tutor] deleting CR within files

Michael Lange klappnase at freenet.de
Thu Apr 15 19:19:14 EDT 2004


On Thu, 15 Apr 2004 11:23:38 -0400
"David Talaga" <dtalaga at novodynamics.com> wrote:

> 
> -----Original Message-----
> From: David Talaga [mailto:dtalaga at novodynamics.com]
> Sent: Thursday, April 15, 2004 10:49 AM
> To: Roger Merchberger
> Subject: RE: [Tutor] deleting CR within files
> 
> 
> Ok, here is what we have now:
> 
> import os
> import Tkinter
> import dialog
> import sys
> import re
> 
> root=Tkinter.Tk()
> f=Tkinter.Button(root, text="Find Files", command=dialog.dialog).pack()
> x=Tkinter.Button(root, text="Close", command=sys.exit).pack()
> 
> sub = re.sub
> fileName= dialog.dialog
> in_file = open(fileName,'r')
> out_file = open(fileName + '_cleaned', 'w')
> for i in in_file.readlines():
>     out_file.write(i[:1] + '\n')
>     print 'File cleaned'
> in_file.close()
> out_file.close()
> 
> Tkinter.mainloop()
> 
> Now when I run it is says this:
> Traceback (most recent call last):
>   File "<pyshell#0>", line 1, in ?
>     execfile('crgui.py')
>   File "crgui.py", line 13, in ?
>     in_file = open(fileName,'r')
> TypeError: coercing to Unicode: need string or buffer, function found
> 
> 
> I did not know that I was using unicode up there...  I am realy at a loss.
> The program runs fine as far ad the dialog box coming up and the print
> statement executing.  I just dont know what the error is saying. Do I need a
> string in place of fileName and if I do how would I go about putting a
> string in there and still trying to call dialog.dialog?  Any help or
> direction would be greatly appreciated and also the option to take my first
> born son. (Not realy, well, OK, if you realy thikn it's a fair trade...)
> 
> David Talaga
> 
> 

Hi David,

what's the "dialog.dialog", a dialog box widget you wrote yourself, I guess? Maybe
it works similar to a tkSimpleDialog.askstring() ? Maybe you just should call

 fileName= dialog.dialog()  ??

Just a shot in the dark, but I think you might have a closer look at the dialog module.

Michael





More information about the Tutor mailing list