Error while running python script

Asked

Viewed 192 times

1

I made this program in python :

//////////color.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-




class Color(object):

    string = {
        "RED": "\x1b[31m",
        "GREEN": "\x1b[32m",
        "BLUE": "\x1b[34m",
        "YELLOW": "\x1b[33m",
        "CYAN": "\x1b[36m",
        "GREY": "\x1b[38;5;247m",
        "ENDC": "\x1b[0m"
    }

    if use_colors in ["off", "OFF"]:
        string = {
            "RED": "",
            "GREEN": "",
            "BLUE": "",
            "YELLOW": "",
            "CYAN": "",
            "GREY": "",
            "ENDC": ""
        }

//hello.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from color import Color as colors

class HelloWorld(object):

    def __init__(self, colors):

           print("%s".format
           (
             self.colors.string["RED"], "Hello ", self.colors.string["ENDC"],
             self.colors.string["GREEN"], "World!"],
             self.colors.string["ENDC"])
           )

but in doing:

$python hello.py

it generates the following error below:

File "hello.py", line 13 self.colors.string["GREEN"], "World!" ], Syntaxerror: invalid syntax

What is the error? Because I tested creating a variable called msg="Hello World" and gives error too.

1 answer

2


There’s an extra square bracket on that line:

self.colors.string["GREEN"], "World!"],
  • 1

    I did not understand the negative vote. What Gustavo said is right.

  • It worked here I ran the program and legal funfou..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.