Python Forum
What is positional argument self?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is positional argument self?
#21
I still don't get why you insist on making your life more complicated by coupling two unrelated things in your class. It's not hard to see how that could get worse: imagine you now want to write the result of a conversion to a file. Would that go in your conversion methods too? Yet more code in there that obscures the real intent of the methods. Each to their own, though.
Reply
#22
Functions are indented at the same level as a class declaration (all the way to the left). Methods are indented one level from the class declaration.

def func(*args):   # Function declaration all way to left
    return sum(args)   # Body is indented one level

class MyClass: # Class declaration all the way to the left
    x = 2  # This is part of the class.  It creates a class variable named "x"

    def method(self, *args):   # Method declaration indented 1 level from class declaration
         return sum(args)    # Method body indented one level from method declaration

    y = 5  # This is still in the class.  Creates a class variable named "y".  Should be up by x = 2.

x = MyClass()  # Code outside any function or method all the way to the left
print(x.method(1, 2, 3, 4))
Reply
#23
Thanks Dean this is going in my note book. This is a synthesis info iv been looking for a while.

ndc, i am not sure what you are referring too;
Quote:coupling two unrelated things in your class.

are you talking about conversionF and conversionC? Cause this is what the book in my python class is asking in the assigment. I do agree the way things are coded in the script is unproductive and even barely logical, but i just follow what has been ask by the teacher.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error: _vhstack_dispatcher() takes 1 positional argument but 9 were given alexfrol86 3 5,713 May-09-2022, 12:49 PM
Last Post: deanhystad
  positional argument: 'self' mcmxl22 8 3,194 Dec-13-2021, 10:11 PM
Last Post: deanhystad
  TypeError: run_oracle_job() missing 1 required positional argument: 'connection_strin python_student 1 1,937 Aug-06-2021, 08:05 PM
Last Post: SheeppOSU
  TypeError: sum() missing 1 required positional argument: 'num2' Insen 3 5,384 Jan-06-2021, 04:25 PM
Last Post: Insen
  TypeError: forward() missing 1 required positional argument: 'x' sveto4ka 4 12,168 Jun-17-2020, 07:25 PM
Last Post: sveto4ka
  missing 1 required positional argument: 'self' yasser 7 11,295 Jun-07-2020, 06:48 AM
Last Post: ndc85430
  TypeError: _linspace_dispatcher() missing 1 required positional argument: 'stop' Ae_Lovecraft 3 8,466 May-28-2020, 03:33 PM
Last Post: Larz60+
  SyntaxError: positional argument follows keyword argument syd_jat 3 5,728 Mar-03-2020, 08:34 AM
Last Post: buran
  Type error: dump() missing 1 required positional argument: fp jaycuff13 2 21,674 Jul-13-2019, 10:21 AM
Last Post: jaycuff13
  missing 1 required positional argument: psosmol 7 13,084 Apr-16-2019, 10:07 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020