Project- Removing dead code in Python with Vulture

5 / 7

Create sample Python script with dead code

Here, we will create a sample Python script with dead code. We will use vi to write the script.

vi is used to:

  • Create and edit the file, if the file doesn't exist.
  • Edit the file, if the file already exists.
  • If we want to create and/or edit the file named myFile, we use vi myFile.

vi has multiple modes: command mode, insert, append mode. In the beginning, it is in command mode. you can type a to change the mode to append mode. Once in append mode, you can type text content.

We pass the commands such as quit file, delete line, search etc in command mode. If you want to change the mode to command mode, press ESC key.

To exit from the file, we press ESC key to go to command mode and type :wq and hit the Enter key. In vi, :wq, w means save, and q means quit.

INSTRUCTIONS
  • Create a file named dead_code.py using vi with the following command:

    vi dead_code.py
    
  • Now enter the following content in the dead_code.py script:

    import os
    
    class Greeter:
        def greet(self):
            print("Hi")
    
    def hello_world():
        message = "Hello, world!"
        greeter = Greeter()
        greet_func = getattr(greeter, "greet")
        greet_func()
    
    if __name__ == "__main__":
        hello_world()
    
See Answer

No hints are availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...