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


Groups > comp.lang.python > #76466

Re: error with files

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 <python-python-list@m.gmane.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.13093.1408356594.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 <module>
>     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)

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


Thread

error with files ngangsia akumbo <ngangsia@gmail.com> - 2014-08-18 02:41 -0700
  Re: error with files Paul Wiseman <poalman@gmail.com> - 2014-08-18 11:07 +0100
    Re: error with files ngangsia akumbo <ngangsia@gmail.com> - 2014-08-18 03:34 -0700
  Re: error with files Peter Otten <__peter__@web.de> - 2014-08-18 12:09 +0200
  Re: error with files Rock Neurotiko <miguelglafuente@gmail.com> - 2014-08-18 11:48 +0200

csiph-web