This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Error with self in python
Type: behavior Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: steven.daprano, tommypm
Priority: normal Keywords:

Created on 2019-04-09 13:25 by tommypm, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pySelf.cmd tommypm, 2019-04-09 13:25 The code used +-
pySelf.py tommypm, 2019-04-09 17:43 The code in Python
Messages (4)
msg339746 - (view) Author: TPM (tommypm) * Date: 2019-04-09 13:25
I try to use self with the __init__ function in a class, but when I enter the other values e.g. def __init__(self, name): self.name = name /// and when I call the class with a name it says that it need another value because it uses self an another value. It happened when I was using Windows 10, but normally I use Linux.
msg339757 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-04-09 14:43
The file you have attached doesn't seem to be a Python script, it seems to be some sort of Windows batch file or similar.

Please supply an actual Python file. (Hint: remove the "del code.py" line from your batch file.) Also, copy and paste the traceback you receive, as text (not a screenshot).

It may help if you read this for ways to submit good bug reports:

http://www.sscce.org/


Thank you.
msg339793 - (view) Author: TPM (tommypm) * Date: 2019-04-09 17:43
The python file.
It works in Linux (Ubuntu) but not in Windows; at least for me.
The output error is : 
Traceback (most recent call last):
  File "pySelf.py", line 8, in <module>
    print(Person.__init__("Some","One",21,"American"))
TypeError: __init__() missing 1 required positional argument: 'nationality'
msg339797 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-04-09 18:06
The error message is correct. The bug is in your code. Also, the code you tell us that you are running is not the same as the code you are actually running.

You should not call __init__ directly as you do:

    # this is wrong
    Person.__init__("Some","One",21,"American")

Do this instead:

    Person("Some","One",21,"American")


Closing this as it is not a bug in Python, it is a bug in your code.
History
Date User Action Args
2022-04-11 14:59:13adminsetgithub: 80755
2019-04-09 18:06:37steven.dapranosetstatus: open -> closed
resolution: not a bug
messages: + msg339797

stage: resolved
2019-04-09 17:43:34tommypmsetfiles: + pySelf.py

messages: + msg339793
2019-04-09 14:43:09steven.dapranosetnosy: + steven.daprano
messages: + msg339757
2019-04-09 13:25:40tommypmcreate