This code in PyCharm is highlighted as an error, how to fix it?

lesson1.py :

 $ telnet www.google.com 80 
  • one
    Add the code, not the link to the screenshot of the code. Describe the problem in more detail: what you want to do, what does not work. - Trymount
  • there is a link to the error and code, Here is the code - $ telnet www.google.com 80; - agre
  • I have everything underlined in red and nothing works, similarly with other libraries - agre
  • where did you read / where did you get it going to work? - Trymount
  • one
    The code must be added to the question, not to the comment, for this there is a "edit" button - Trymount

1 answer 1

You cannot write commands in Python code that you write on the command line.

To execute such commands in Python, you need to call them with a special method:

 import subprocess result = subprocess.run(["telnet", "www.google.com", "80"], stdout=subprocess.PIPE) # на экране будет выведен результат работы команды # и информация об объекте result (экземпляр класса CompletedProcess) print(result, dir(result)) 

More details about running commands from Python code can be found in the official documentation for the subprocess module.

  • and instead of an external command, you can use socket, telnetlib, urlopen() , depending on your needs. - jfs