[Tutor] Need help appending data to a logfile

Matt D md123 at nycap.rr.com
Fri Jun 28 00:19:30 CEST 2013


On 06/27/2013 05:55 PM, eryksun wrote:
> On Thu, Jun 27, 2013 at 5:09 PM, Matt D <md123 at nycap.rr.com> wrote:
>> I use gedit.  Yes sir, its all spaces, I'm not putting you on there are
>> no tabs in my .py file. none.  I am pretty sure if i knew how to put the
>> proper code after the 'with open()' thing, indented of course, that the
>> indentation error would be gone.  But Ive been looking at the shutil
>> thing and i can not figure out how to write the right code to go after
>> the 'open with()' that will make whats in 'logfile.txt' get appended
>> into whatever file the user opens.
> 
> The code you pasted earlier uses tabs, except for the last line:
> 
>     >>> print(src.replace('\t', 'tab>'))
>     tab>def openFile(self, evt):
>     tab>tab>with wx.FileDialog(self, "Choose a file", os.getcwd(), "",
>     tab>                        "*.*", wx.OPEN) as dlg:
>     tab>tab>tab>if dlg.ShowModal() == wx.ID_OK:
>     tab>tab>tab>tab>path = dlg.GetPath()
>     tab>tab>tab>tab>mypath = os.path.basename(path)
>                                     with open(mypath, "a") as f:
> 
> Maybe tabs are being replaced with 8 spaces, while the rest of your
> code uses 4-space indents. Note that the final "with open" is indented
> by 32 spaces instead of 16:
> 
>     >>> src.splitlines()[-1].find('with')
>     32
> 
> Just make sure you're indenting consistently. I use dotted indentation
> guides and visible spaces/tabs. It makes the edit window noisy, but I
> don't really notice it.
> 
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.


More information about the Tutor mailing list