解耦是做什么的,导入配置是做什么的?

时间:2020-08-03 13:44:14

标签: python

我从Kalle Hallden的video中看到了一个有趣的想法。它用于在有人的IP连接到网络时提醒您。我以为复制代码并使用它会真的很有趣,但是我在python中不是很出色,并且遇到了一些麻烦。

在第三行中,当我将其放在代码from decouple import config中时,它是decouple,并且config用红色下划线表示。我知道这是某种错误,但我不知道如何解决。我希望这里有人可以帮助我。谢谢。

代码

import sys
import subprocess
import os
from decouple import config

IP_NETWORK = config('IP_NETWORK')
IP_DEVICE = config('IP_DEVICE')

proc = subprocess.Popen(["ping", IP_NETWORK],stdout=subprocess.PIPE)
while True:
  line = proc.stdout.readline()
  if not line:
    break
  #the real code does filtering here
  connected_ip = line.decode('utf-8').split()[3]

  if connected_ip == IP_DEVICE:
      subprocess.Popen(["say", "Linnea just connected to the network"])

1 个答案:

答案 0 :(得分:0)

点安装python-decouple

此命令将安装解耦库,并允许您进一步使用它。