-5

What is causing this error? Isn't it possible commenting out lines like this inside code?

for i in (Class_1, """Class_2, Class_3"""):
    name = i.__name__

Class_1, Class_2 and Class_3 are classes declared before the upper code.

Error output:

> Traceback (most recent call last):
  File "", line 2, in <module>
    name = i.__name__
AttributeError: 'str' object has no attribute '__name__'

Process finished with exit code 1

Error message line edited to fit the example code

  • This question is off-topic. The error message is just a consequence of trying to use a block comment in Python. These would've solved my issue: [Is there a way to create multiline comments in Python?](https://stackoverflow.com/questions/7696924/is-there-a-way-to-create-multiline-comments-in-python) and [How to comment out a block of code in Python](https://stackoverflow.com/questions/675442/how-to-comment-out-a-block-of-code-in-python) – Andreas is moving to Codidact Jul 16 '20 at 11:24

2 Answers2

2

Remove the triple-quoted string """Class_2, Class_3""" to avoid iterating over it which is what you're doing in this case so it looks like for i in (Class_1,) (parenthesis are optional).

It seems you want to comment out those unnecessary sides, but please note that those triple-quotes strings technically aren't comments, so they can still affect the script in some areas you didn't intend.

TidB
  • 1,749
  • 1
  • 12
  • 14
1

What do you mean by

for i in (Class_1, """Class_2, Class_3"""):

When you iterate over this tuple, the second element is a string, thus causing the error.

laike9m
  • 18,344
  • 20
  • 107
  • 140