FW: [Tutor] deleting CR within files
David Talaga
dtalaga at novodynamics.com
Fri Apr 16 14:00:00 EDT 2004
Here is the whole thing. See what you can do? I am stuck and sitting here
looking at it doesn't help my situation...
#This is the dialog.py module:
from Tkinter import *
import tkFileDialog
import sys
def dialog(fileName):
top = Tk()
top.withdraw()
initDir = 'C:/windows/desktop'
filetype = [('All files', '.*')]
fileName = tkFileDialog.askopenfilename(initialdir=initDir,
filetypes=filetype)
return fileName
And here is the crgui.py module:
import os
import Tkinter
import sys
import dialog
root=Tkinter.Tk()
f=Tkinter.Button(root, text="Find Files", command=dialog.dialog).pack()
x=Tkinter.Button(root, text="Close", command=sys.exit).pack()
if f:
in_file = open(fileName,'r').readlines()
out_file = open(fileName + '_cleaned', 'w')
for i in dialog().readline:
out_file.write(i[:-1] + '\n')
print 'File cleaned'
out_file.close()
print filename
root.mainloop()
The dialog function is not returning the information I believe. I think
this is where my problem lies. I am not able to access the text i am trying
to access because I believe that for some reason I am not getting the actual
file, just a printed version of it.
David Talaga
-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On
Behalf Of Michael Lange
Sent: Thursday, April 15, 2004 7:19 PM
To: tutor at python.org
Subject: Re: FW: [Tutor] deleting CR within files
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
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040416/6e9535f3/attachment.html
More information about the Tutor
mailing list