<!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">
(Guilty again of not hitting Reply All. I responded (to Kent) 8 hours
ago. If anyone is against the controversial way this mail list handles
replies, put me at the top of the list. In my book this list is unique
in the way it handles replies.)<br>
<br>
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. At the bottom of
the page, he mentions English is not his language, and might need some
help on the wiki entry. A <u>very</u> helpful example though.<br>
<br>
First,<br>
<pre dir="ltr" id="CA-6642c899acd15ca6d3ae7df9485bcf6929fafdc8_000"
lang="en"><span class="line"><span class="LineNumber"> 60 </span> <span
class="ResWord">def</span> <span class="ID">asksaveasfile</span><span
class="Operator">(</span><span class="ID">self</span><span
class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 61 </span></span>
<span class="line"><span class="LineNumber"> 62 </span> <span
class="String">"""Returns an opened file in write mode."""</span></span>
<span class="line"><span class="LineNumber"> 63 </span></span>
<span class="line"><span class="LineNumber"> 64 </span> <span
class="ResWord">return</span> <span class="ID">tkFileDialog</span><span
class="Operator">.</span><span class="ID">asksaveasfile</span><span
class="Operator">(</span><span class="ID">mode</span><span
class="Operator">=</span><span class="String">'w'</span><span
class="Operator">,</span> <span class="Operator">**</span><span
class="ID">self</span><span class="Operator">.</span><span class="ID">file_opt</span><span
class="Operator">)</span></span></pre>
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?<br>
<br>
BTW, I printed out the return from line 64 and got:<br>
<open file 'C:/myfile.txt', mode 'w' at 0x0519D4A0><br>
<br>
I may be misinterpreting this, but I took it as a file name, while it
really may be the representation for an object. That makes sense now,
since it certainly isn't just myfile.txt.<br>
<br>
Next consider:<br>
<pre dir="ltr" id="CA-6642c899acd15ca6d3ae7df9485bcf6929fafdc8_000"
lang="en"><span class="line"><span class="LineNumber"> 66 </span> <span
class="ResWord">def</span> <span class="ID">asksaveasfilename</span><span
class="Operator">(</span><span class="ID">self</span><span
class="Operator">)</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 67 </span></span>
<span class="line"><span class="LineNumber"> 68 </span> <span
class="String">"""Returns an opened file in write mode.</span></span>
<span class="line"><span class="LineNumber"> 69 </span><span
class="String"> This time the dialog just returns a filename and the file is opened by your own code.</span></span>
<span class="line"><span class="LineNumber"> 70 </span><span
class="String"> """</span></span>
<span class="line"><span class="LineNumber"> 71 </span></span>
<span class="line"><span class="LineNumber"> 72 </span> <span
class="Comment"># get filename</span></span>
<span class="line"><span class="LineNumber"> 73 </span><span
class="Comment"></span> <span class="ID">filename</span> <span
class="Operator">=</span> <span class="ID">tkFileDialog</span><span
class="Operator">.</span><span class="ID">asksaveasfilename</span><span
class="Operator">(</span><span class="Operator">**</span><span
class="ID">self</span><span class="Operator">.</span><span class="ID">file_opt</span><span
class="Operator">)</span></span>
<span class="line"><span class="LineNumber"> 74 </span></span>
<span class="line"><span class="LineNumber"> 75 </span> <span
class="Comment"># open file on your own</span></span>
<span class="line"><span class="LineNumber"> 76 </span><span
class="Comment"></span> <span class="ResWord">if</span> <span
class="ID">filename</span><span class="Operator">:</span></span>
<span class="line"><span class="LineNumber"> 77 </span> <span
class="ResWord">return</span> <span class="ID">open</span><span
class="Operator">(</span><span class="ID">filename</span><span
class="Operator">,</span> <span class="String">'w'</span><span
class="Operator">)</span></span></pre>
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.
<br>
<br>
Kent Johnson wrote:
<blockquote
cite="mid:1c2a2c590902061817pbf1946fva9643a0b4983bbc5@mail.gmail.com"
type="cite">
<pre wrap="">On Fri, Feb 6, 2009 at 6:53 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="">I'm using asksaveasfilename, and, as I understand it, it returns the file
name to me in write mode. I don't recall that there's a way to reference the
file with only the filename. That is, there's no filename.write(). Comments?
</pre>
</blockquote>
<pre wrap=""><!---->
I think you are confused between askopenfile() and askopenfilename().
The first opens the file and returns a file object, the second returns
just the file name and you open the file yourself.
</pre>
<blockquote type="cite">
<pre wrap="">While I'm at it, I have found a good example program for TkFileDialog
methods, but the description of them on the internet is pretty shallow. For
example, An Intro to Tkinter, Lundh's Tkinter pages, NM Tech pdf files and
Python docs have little to say.
</pre>
</blockquote>
<pre wrap=""><!---->
This is helpful:
<a class="moz-txt-link-freetext"
href="http://tkinter.unpythonic.net/wiki/tkFileDialog">http://tkinter.unpythonic.net/wiki/tkFileDialog</a>
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>