#๐Ÿ”’ Is that right? If not, where is my erros?

46 messages ยท Page 1 of 1 (latest)

sonic ice
#
class Foo:
  def__init__(self, name)
  self.name = name


class Too(Foo):
  def__init__(self, thing)
  super.()__init__(Fooo)
  self.thing = thing

print(name, thing)
glossy lightBOT
#

@sonic ice

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

still salmon
#

so with python you use indents and colons to define a scope

#

this would be done when making a function or a class

#
class Foo:
  def __init__(self, name):
    self.name = name

class Too(Foo):
  def __init__(self, thing):
    super.()__init__(Fooo)
    self.thing = thing

print(name, thing)
#

seems like some other stuff is wrongf

candid flower
#

still missing :

still salmon
#

mb

candid flower
#

your super call is also wrong

#

super().__init__()

#

super.()__init__(Fooo)

still salmon
#

also name and thing isnt defined in the global scope

candid flower
#

yes it is, it's a parameter of the method

still salmon
#

I mean for when they try to print it

candid flower
#

ahh in that case, yes

#

oh sorry you said global

#

my mistake

still salmon
#

if you want to call it directly you could call it form the class

class Foo:
  def __init__(self, name):
    self.name = name

class Too(Foo):
  def __init__(self, thing):
    super().__init__(Fooo)
    self.thing = thing

print(Foo.name, Too.thing)
candid flower
#

it would be Foo('Fashoomp').name

#

name and thing are instance attributes

still salmon
#

ur right

candid flower
#

make sure to pass in an argument

still salmon
#

but you also cant just call it directly since you never gave a direct value for them either

still salmon
#

that and a typo on line 7. it should be Foo not Fooo

candid flower
#

it doesn't need that at all

#

super().__init__()

#

no need to pass in the class name

still salmon
#

so if I understand your goal correctly it should be

class Foo:
  def __init__(self, name):
    self.name = name

class Too(Foo):
  def __init__(self, thing):
    super().__init__(Foo)
    self.thing = thing

print(Foo("Bar").name, Too("Par").thing)
still salmon
candid flower
#

you would need to pass it a name

#

so Too class should either be passing in a default value or the init should be asking for name and thing

sonic ice
still salmon
#

1st. use tab buttons for indents

#

if you want to indent once, only hit tab once

#

example:

def foo():
  print("bar")
sonic ice
#

class Foo:
    def __init__(self, name):
         self.name = name


class Too(Foo):
    def __init__(self, thing):
        super().__init__(Foo)
        self.thing = thing


print(name="The", thing="Rock")

still salmon
#

almost. when working with a function you want to assign the variable inside by using ()

#

so it would be name("the")

#

id reccomend looking at beginner python guides to fully understand the syntax and then moving on to OOP

sonic ice
#

it worked now, thanks my dudes

#

my goal was to understand the super()

#

!close

glossy lightBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.