Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'argument': 0.05; 'data:': 0.09; 'latter': 0.09; 'os.path': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:files': 0.09; 'python': 0.11; "'w')": 0.16; 'convey': 0.16; 'file1': 0.16; 'file_name': 0.16; 'given)': 0.16; 'method;': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'typeerror:': 0.16; 'write.': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'import': 0.22; 'preferred': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'equivalent': 0.26; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'correct': 0.29; 'thus': 0.29; 'invoke': 0.31; 'file': 0.32; '(most': 0.33; 'subject:with': 0.35; 'skip:o 20': 0.38; 'to:addr :python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'name:': 0.61; 'providing': 0.61 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: error with files Date: Mon, 18 Aug 2014 12:09:38 +0200 Organization: None References: <77b81003-3a5d-4a54-b609-e0f0b6f1d0de@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd8e81.dip0.t-ipconnect.de User-Agent: KNode/4.13.2 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408356594 news.xs4all.nl 2866 [2001:888:2000:d::a6]:54809 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76466 ngangsia akumbo wrote: > error > > yems ~ # nano testfile1 > yems ~ # python testfile1 > Enter file name: g > write in data: g > Traceback (most recent call last): > File "testfile1", line 11, in > file.write(file1) > TypeError: function takes exactly 1 argument (0 given) > > > > import os.path > > save_here = '/home/yems/newfile/' > file_name = raw_input("Enter file name: ") > filesname = os.path.join(save_here, file_name+".txt") > > file1 = open(filesname, 'w') > > file_data = raw_input('write in data: ') > > file.write(file1) > > file1.close() file is a built-in type and file.write(file1) is roughly equivalent to file1.write() The latter is the preferred way to invoke the method; thus the (confusing) error message > TypeError: function takes exactly 1 argument (0 given) is trying to convey that you are not providing any data to write. The correct call instead of > file.write(file1) is then file1.write(file_data)