<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Yes, amazingly enough, I'm quite familiar with basic file operations.
:-) I'm certainly no expert at all variations of it. <br>
<br>
Output from the sample program:<br>
<br>
1.<br>
<blockquote>file is open and ready for writing.<br>
Here's return for asksaveasFILE: <open file 'C:/myfile.txt', mode
'w' at 0x058E1DA0><br>
</blockquote>
2.<br>
<blockquote>you opened in write mode. return for asksaveasfileNAME:
C:/myfile.txt<br>
</blockquote>
<br>
In 1, the return is an object, and 2 it's a file name, correct?<br>
<br>
I may be mistaken, but I do not think any of the documentation I've
seen on these two methods states what type of result is produced. That
is really my point. I had to find out the hard way by printing out the
result. <br>
<br>
In any case, the "correct" method of the two that I need is working in
my program. <br>
<br>
Now for a related question. I'm using Win XP. One of the arguments is
the default_path. I would like it to be the same folder the program is
in. How do I do that? "c:/.", "./", or some variation? <br>
<br>
Amazingly, I hit Reply to All. :-)<br>
<br>
Kent Johnson wrote:
<blockquote
cite="mid:1c2a2c590902070451s2e9d6f15r2cd0fc6ee4581c30@mail.gmail.com"
type="cite">
<pre wrap="">On Fri, Feb 6, 2009 at 9:59 PM, Wayne Watson
<a class="moz-txt-link-rfc2396E" href="mailto:sierra_mtnview@sbcglobal.net"><sierra_mtnview@sbcglobal.net></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Yes, I probably confused the two. The link you mentioned is the one I found
most helpful of the ones I mentioned. Note that his descriptions here, like
others, and to me at least, are minimal.
</pre>
</blockquote>
<pre wrap=""><!---->
I think, as Alan says, there just is not much to say, and that you are
missing, or misinterpreting, what is there. Are you familiar with
basic file operations in Python (open, read, write)?
</pre>
<blockquote type="cite">
<pre wrap="">First,
60 def asksaveasfile(self):
61
62 """Returns an opened file in write mode."""
63
64 return tkFileDialog.asksaveasfile(mode='w', **self.file_opt)
Although, his description in the table doesn't mention the return type, it
would seem like it should be the file name. However, the comment says the
file is open. OK, how do you write on it? Where's the object? OK, I see you
say it is an object. I'm sure you're right, but how do you know?
</pre>
</blockquote>
<pre wrap=""><!---->
When you call
f = open('myfile.txt', 'w')
the returned value is a file object representing an opened file in
write mode. You write to it by calling the write() method:
f.write('some text')
The value returned from asksaveasfile() is the same - an object
representing an opened file.
</pre>
<blockquote type="cite">
<pre wrap="">BTW, I printed out the return from line 64 and got:
<open file 'C:/myfile.txt', mode 'w' at 0x0519D4A0>
I may be misinterpreting this, but I took it as a file name, while it really
may be the representation for an object.
</pre>
</blockquote>
<pre wrap=""><!---->
Yes, it is the representation of a file object. Many objects are
represented similarly if they don't have a reasonable literal
representation.
</pre>
<blockquote type="cite">
<pre wrap="">Next consider:
66 def asksaveasfilename(self):
67
68 """Returns an opened file in write mode.
69 This time the dialog just returns a filename and the file is opened
by your own code.
70 """
71
72 # get filename
73 filename = tkFileDialog.asksaveasfilename(**self.file_opt)
74
75 # open file on your own
76 if filename:
77 return open(filename, 'w')
Here, the file is not opened, and one is on their own. So
output=open(filename,'w') will open it for writing. No difficulty here.
</pre>
</blockquote>
<pre wrap=""><!---->
Yes, and notice that the description of the returned object is
identical to that for asksaveasfile().
Kent
</pre>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<meta content="text/html;" http-equiv="Content-Type">
<title>Signature.html</title>
<pre class="moz-signature" cols="76"> Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
(121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)
<font color="#330099"> </font>
<b><b style="color: rgb(204, 51, 204);" class="b"><span
style="font-family: monospace;"> Q: What do you do when your resistors get to hot?
A: Open the switch and coulomb they off.
-- Anon. (fortunately!)
</span><span style="font-family: monospace; color: rgb(153, 51, 153);"></span></b></b><b
style="color: rgb(204, 51, 204);" class="b"><span
style="font-family: monospace; color: rgb(153, 51, 153);"></span></b><span
style="color: rgb(153, 51, 153);"></span><span
style="color: rgb(153, 51, 153);">
</span><span style="color: rgb(153, 51, 153);"></span><b
style="color: rgb(204, 51, 204);" class="b"><span
style="font-family: monospace;"></span></b><span
style="color: rgb(204, 51, 204);"></span> Web Page: <<a class="moz-txt-link-abbreviated" href="http://www.speckledwithstars.net/">www.speckledwithstars.net/</a>></pre>
</div>
</body>
</html>