可以引用局部变量

时间:2018-03-06 00:21:39

标签: python pycharm scapy

pack = IP(dst=target)/ICMP()
resp = sr1(pack, timeout=2)

if resp == None:
 self.output_console ("no response")
elif IP in resp:
 if resp.getlayer(IP).ttl <= 64:
    self.output_console("*"*20)
    os = 'This Pc is using Linux'

else:
    os1 = "This Pc is using Windows"
self.output_console ("ttl value %d => %s"%(resp.getlayer(IP).ttl)+ os)
self.output_console("*"*20)

本地变量“os”可能会被引用你能帮我解决这个问题吗

2 个答案:

答案 0 :(得分:2)

当你到达这一行时,警告告诉你:

os

名称self.output_console ("ttl value %d => %s"%(resp.getlayer(IP).ttl)+ os) 可能尚未绑定到任何对象。这将是os的崩溃。这可能是因为您在一个分支中使用NameError作为名称,然后在另一个分支中使用os作为名称。

顺便说一下,检查Linux或Windows是否是这样的规范方法:

os1

答案 1 :(得分:0)

# GAMLSS model.frame workaround for dplyr # See https://stackoverflow.com/q/48979322/152860 model.frame.gamlss <- function(formula, what = c("mu", "sigma", "nu", "tau"), parameter = NULL, ...) { object <- formula dots <- list(...) what <- if (!is.null(parameter)) { match.arg(parameter, choices = c("mu", "sigma", "nu", "tau")) } else match.arg(what) Call <- object$call parform <- formula(object, what) data <- if (!is.null(Call$data)) { ## problem here, as Call$data is . #eval(Call$data) # instead, this would work: eval(Call$data, environment(formula$mu.terms)) } else { environment(formula$terms) } Terms <- terms(parform) mf <- model.frame( Terms, data, xlev = object[[paste(what, "xlevels", sep = ".")]] ) mf } # broken mro <- mtcars %>% nest(-am) %>% mutate(am = factor(am, levels = c(0, 1), labels = c("automatic", "manual")), fit = map(data, ~gamlss(mpg ~ hp + wt + disp, data = .)), results = map(fit, augment)) 是标准库中的包。将它用作变量名称

可能不是一个好主意