-3
class Myclass(object):
    def __init__(self , msg , integer):
    self.msg = msg
    self.integer = integer
    print (self.msg)
    print (self.integer)
    return

Error

File "<input>", line 3
    self.msg = msg
       ^
IndentationError: expected an indented block
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
m0m0c4t
  • 1
  • 1

2 Answers2

0

This question is a duplicate, and fyi Python2 allows mixed usage of tabs and spaces but Python3 does not. It recommends using spaces for uniformity. Please check PEP8 for more info:

https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces

EDIT: And please indent after defining a function. It must be all indented up to the code block.

Joseph Seung Jae Dollar
  • 1,016
  • 4
  • 13
  • 28
0
class Myclass(object):
    def __init__(self , msg , integer):
        self.msg = msg
        self.integer = integer
        print (self.msg)
        print (self.integer)
        return

Whitespace matters in python.

Edit: Ran without issues

>>> class MyClass(object):
...  def __init__(self, msg, integer):
...   self.msg=msg
...   self.integer = integer
...   print(self.msg)
... 
>>> x = MyClass('foo', 5)
foo
T.Woody
  • 1,142
  • 2
  • 11
  • 25
  • it dind't work so strange :/ – m0m0c4t Aug 27 '18 at 11:22
  • @m0m0c4t what did you try and what is the error message? – T.Woody Aug 27 '18 at 18:00
  • File "", line 3 self . msg = msg ^ IndentationError: expected an indented block – m0m0c4t Aug 27 '18 at 20:20
  • still same error @T.Woody – m0m0c4t Aug 27 '18 at 20:21
  • @m0m0c4t I just tested the code in terminal, for an output to put here. Please try the same, and get back to me... – T.Woody Aug 27 '18 at 21:08
  • I solved the problem I'm new in coding but I tried this and did work: def __init__(self,msg,integer) #not: .../(self , msg , integer) – m0m0c4t Aug 27 '18 at 22:59
  • @m0m0c4t I can assure you that spaces in your parameter block would not change anything when the code is compiled. – T.Woody Aug 27 '18 at 23:02
  • I use python 3.7 and pycharm for IDE and in pyCahrm spaces in matters cause the program can not identify the lib sometimes I don't know why but it works like that sounds ridiculous Im new in coding but I'm researching whole day it must not be like this but it happens.. – m0m0c4t Aug 28 '18 at 07:49
  • @m0m0c4t I am sorry, but that is not the case. Things do not just decide to act a certain way sometimes and we can't figure it out. I am not new and coding, and I am informing you: That is not how it works. – T.Woody Aug 28 '18 at 18:33
  • I got it ; thank you for helping me and I'm sorry that if I bothered you ^^ – m0m0c4t Aug 28 '18 at 20:36