Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76464 > unrolled thread
| Started by | ngangsia akumbo <ngangsia@gmail.com> |
|---|---|
| First post | 2014-08-18 02:41 -0700 |
| Last post | 2014-08-18 11:48 +0200 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.python
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
| From | ngangsia akumbo <ngangsia@gmail.com> |
|---|---|
| Date | 2014-08-18 02:41 -0700 |
| Subject | error with files |
| Message-ID | <77b81003-3a5d-4a54-b609-e0f0b6f1d0de@googlegroups.com> |
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()
[toc] | [next] | [standalone]
| From | Paul Wiseman <poalman@gmail.com> |
|---|---|
| Date | 2014-08-18 11:07 +0100 |
| Message-ID | <mailman.13092.1408356439.18130.python-list@python.org> |
| In reply to | #76464 |
The line should be:
file1.write(file_data)
you could write
file.write(file1, file_data)
but that would be an odd way to do it :)
On 18 August 2014 10:41, ngangsia akumbo <ngangsia@gmail.com> 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()
> --
> https://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [next] | [standalone]
| From | ngangsia akumbo <ngangsia@gmail.com> |
|---|---|
| Date | 2014-08-18 03:34 -0700 |
| Message-ID | <a218d59a-12f0-4fcc-a14a-92278c1838e3@googlegroups.com> |
| In reply to | #76465 |
Thanks guys
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-08-18 12:09 +0200 |
| Message-ID | <mailman.13093.1408356594.18130.python-list@python.org> |
| In reply to | #76464 |
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)
[toc] | [prev] | [next] | [standalone]
| From | Rock Neurotiko <miguelglafuente@gmail.com> |
|---|---|
| Date | 2014-08-18 11:48 +0200 |
| Message-ID | <mailman.13094.1408358720.18130.python-list@python.org> |
| In reply to | #76464 |
[Multipart message — attachments visible in raw view] — view raw
You are trying to write the open file (file1) in the file type.
I think that you wanted to write in file1, the data:
file1.write(file_data) # instead of file.write(file1)
2014-08-18 11:41 GMT+02:00 ngangsia akumbo <ngangsia@gmail.com>:
> 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()
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
Miguel García Lafuente - Rock Neurotiko
Do it, the devil is in the details.
The quieter you are, the more you are able to hear.
Happy Coding. Code with Passion, Decode with Patience.
If we make consistent effort, based on proper education, we can change the
world.
El contenido de este e-mail es privado, no se permite la revelacion del
contenido de este e-mail a gente ajena a él.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web