Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73384

Python Fails to Write to File

Newsgroups comp.lang.python
Date 2014-06-18 16:03 -0700
Message-ID <8aaa4195-af5c-4ba3-a891-b1f268c086ac@googlegroups.com> (permalink)
Subject Python Fails to Write to File
From cutey Love <cuteywithlove@gmail.com>

Show all headers | View raw


I'm trying to write data to a text file

But I'm getting the error:

TypeError: invalid file: <_io.TextIOWrapper 

Code is 

def saveFile():
    file_path = filedialog.asksaveasfile(mode='w', filetypes=[('text files', '.txt')], defaultextension=".txt")
    fo = open(file_path, 'w')
    
    for e in myList:
        fo.write(e)
            
    
    fo.close()

The file is being created if not already present but no data is written

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Python Fails to Write to File cutey Love <cuteywithlove@gmail.com> - 2014-06-18 16:03 -0700
  Re: Python Fails to Write to File Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-18 17:18 -0600
  Re: Python Fails to Write to File Paul McNett <paul@mcnettware.com> - 2014-06-18 16:20 -0700
  Re: Python Fails to Write to File cutey Love <cuteywithlove@gmail.com> - 2014-06-19 00:54 -0700
    Re: Python Fails to Write to File Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-06-19 09:39 +0100

csiph-web