[Tutor] Need help appending data to a logfile

Matt D md123 at nycap.rr.com
Thu Jun 27 18:33:40 CEST 2013


> 
>   <SNIP>
>> I forgot to mention i have the 'with open(mypath, "a") as f: commented
>> out because it was making an indentation error that i could not fix.
> 
> It was indented, and should not have been.  The extra indentation
> FOLLOWS the with statement, it's not correct to indent the line itself.
> 
> Line it up with mypath=
> 
> Isn't the rule for indentation simple enough?  If a line ends with a
> colon, you indent the next line.  And keep indenting till the scope of
> that colon ends.  I don't know of any exceptions, but if there are any,
> they're rare.  Anyway, when the compiler complains, there aren't many
> choices on how to change the line, so experimentation should teach you
> pretty quickly.
> 
> Maybe you're getting confused about indentation because your editor
> doesn't handle tabs correctly.  If you mix tabs and spaces, you'll drive
> yourself crazy, at least with 2.x   Python 3 tells you about it with a
> new error.  The easy answer (and my strong preference) is to never use
> tabs in Python sources.  Expand all your existing tabs (to 4 column
> intervals), and tell your editor to always expand the tab key when
> entering.
> 
> I suggest you fix this problem first, and understand the fix, before
> going off and using shutil.copy().
> 
> 
Thanks!  I do have 'with open(mypath, "a") as f:' lined up with the
mypath line above (not sure why it indented with the paste to email) and
I already replaced all tabs with spaces. seriously there is not one
single tab in the whole program. but when that line is not commented out
the program bails with the indentation error, other wise its fine.  .
So i don't know what i can do about that.
Thanks!


More information about the Tutor mailing list