[Tutor] Need help appending data to a logfile

eryksun eryksun at gmail.com
Fri Jun 28 00:39:07 CEST 2013


On Thu, Jun 27, 2013 at 6:19 PM, Matt D <md123 at nycap.rr.com> wrote:
> yeah its not like that in my .py file. i think im doing something weird
> when i paste into my email.  is use only spaces in my .py file.  and the
> 'with open()' is lined up with the 'mypath'.  I get the indentation
> error because i dont have any code under the 'with open()' line to get
> done what i need.  which is to copy logfile.txt into whatever file the
> user chooses in the file dialog.

Sorry, I didn't know what to make of the "the proper code after 'with
open'". I should have asked. I assumed you still had a statement
there, like what you had before, i.e. f.writelines(self.log_array).

Compound statements (if/elif/else, try/except/finally, while, for,
with, def, class) have a colon followed by one (not zero) or more
statements. A simple statement can go on the same line after the
colon. Otherwise use an indented block. In this case you can simply
use:

    with open(mypath, "a") as f: pass


More information about the Tutor mailing list