Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
__init__ function arguments
#1
Hello,

I am trying to make an __init__ function's argument be the previous argument of that function divided by 2.

class item:
    def __init__(self,value1,value2):
        self.v1 = value1
        self.v2 = value2

x = item(10,item.v1/2)
However, when I run it I get the message that "type object 'item' has no attribute v1".

Any other ways to do it?
Reply


Messages In This Thread
__init__ function arguments - by CoderMan - Jan-18-2019, 12:41 PM
RE: __init__ function arguments - by Larz60+ - Jan-18-2019, 01:58 PM
RE: __init__ function arguments - by CoderMan - Jan-27-2019, 04:09 AM
RE: __init__ function arguments - by snippsat - Jan-18-2019, 02:51 PM
RE: __init__ function arguments - by stullis - Jan-27-2019, 02:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  function arguments Curbie 2 495 Apr-30-2025, 05:23 PM
Last Post: Curbie
  calling external function with arguments Wimpy_Wellington 6 3,099 Jul-05-2023, 06:33 PM
Last Post: deanhystad
  'namespace' shorthand for function arguments? shadowphile 5 3,741 Aug-11-2021, 09:02 PM
Last Post: shadowphile
  Checking the number of arguments a function takes Chirumer 3 3,065 Jul-06-2021, 04:56 PM
Last Post: Chirumer
  How to deal with self and __init__ in function MrFloyd_telomerase 1 2,344 Apr-26-2021, 08:15 PM
Last Post: buran
  Possible to dynamically pass arguments to a function? grimm1111 2 3,002 Feb-21-2021, 05:57 AM
Last Post: deanhystad
  How to pass multiple arguments into function Mekala 4 3,546 Jul-11-2020, 07:03 AM
Last Post: Mekala
  How to give a name to function arguments in C-API? WonszZeczny 0 1,843 Jun-22-2020, 10:20 AM
Last Post: WonszZeczny
  Function Recognises Variable Without Arguments Or Global Variable Calling. OJGeorge4 1 3,114 Apr-06-2020, 09:14 AM
Last Post: bowlofred
  Pass Arguments to Function phillyfa 2 3,143 Mar-27-2020, 12:05 PM
Last Post: phillyfa

Forum Jump:

User Panel Messages

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