python输错了怎么返回_Python如果返回错误(Python if is returning wrong)

Python如果返回错误(Python if is returning wrong)

我有一个if语句来检查两个变量是否返回相同,这意味着客户端存在。 现在if语句应该是真的,我不明白为什么它不是。

client_status= subprocess.check_output("nsostatus | grep %s | awk '{ print $1 }'" %client_name, shell=True)

print client_name

print client_status

if client_name == client_status:

print "client already exist"

else:

print "client doesn't exist"

当我运行脚本时,这就是我得到的:

nagios-client

nagios-client

client doesn't exist

编辑:用repr()运行它

nagios-client

nagios-client\n

I have a if statement to check if two variables returns the same, which means the client exist. Right now the if statement should be true, I dont understand why it doesn't.

client_status= subprocess.check_output("nsostatus | grep %s | awk '{ print $1 }'" %client_name, shell=True)

print client_name

print client_status

if client_name == client_status:

print "client already exist"

else:

print "client doesn't exist"

When I run the script, this is what I get:

nagios-client

nagios-client

client doesn't exist

EDIT: Running it with repr()

nagios-client

nagios-client\n

原文:https://stackoverflow.com/questions/28648192

2020-04-19 07:04

满意答案

它可能是一个尾随的新行或空白

“\ n”

要么

“”

......试试......

if client_name.strip() == client_status.strip():

It could be a trailing new-line or whitespace

"\n"

or

" "

... try...

if client_name.strip() == client_status.strip():

2015-02-21

相关问答

您正在正确导入这些函数: from langpy import lang

from langpy import port

但是,您正在打印对这些功能的引用 ,而不是返回值。 print(str(lang))

print(str(port))

你想实际调用函数,然后打印返回的内容。 你可以这样做: print(str(lang()))

print(str(port()))

还有一组括号! 编辑:进一步观察,你也没有从你的功能返回任何东西。 尝试: def lang():

...

kFold迭代器为您提供DataFrame的训练和验证对象的位置索引,而不是它们的非连续索引。 您可以使用.iloc pandas方法访问您的火车和验证对象: kFold = KFold(n_splits=10, shuffle=True, random_state=None)

for train_index, test_index in kFold.split(dfNARemove):

train_data = dfNARemove.iloc[train_index]

test_...

正如文档所述 : ddof : int, optional

"Delta Degrees of Freedom": the divisor used in the calculation is

``N - ddof``, where ``N`` represents the number of elements. By

default `ddof` is zero.

所以你有: >>> numpy.var([0.82159889, 0.26007962, 0.098184...

将您的查询更新为: $query->where('first_name', 'like', "%".$agent_name."%");

你在LIKE的开头和结尾有一个额外的' 。 Update your query to: $query->where('first_name', 'like', "%".$agent_name."%");

You had a extra ' at the start and end of the LIKE.

如果您100%确定要处理同一个数据库,则可能正在使用较新的SQLite库版本和命令行工具。 您可以验证正在使用的版本: print sqlite.sqlite_version

在Python和 sqlite3 -version

使用命令行工具。 您可以检查sqlite3更改日志以查看是否有任何相关更改,或者您只需将SQLite3 DLL更新为最新版本,以确保您没有遇到错误或新功能。 If you are 100% certain that you are dealing with the sa...

问题是4.0不在数组中。 一个非常接近4.0的值,但略微偏离(由于浮点不准确)在数组中,当您打印它时,打印例程将四舍五入为“4.0”以进行显示。 如果你打印出实际的元素( loggs[5] ),python将以更高的精度打印,你会看到该值实际上略高于4.0 (约4.0000000000000018 )。 我建议阅读每个计算机科学家应该知道的有关浮点运算的内容,以获取更多详细信息。 The problem is that 4.0 is not in the array. A value very c...

Python不知道哪个实际参数出错,只是它是从一个延伸几行的表达式传递过来的。 它粗略地猜测了错误行( Ryan在评论中指出这似乎是表达式中最后一个非标点行),并报告错误来自那里,但它可能来自任何部分错误的表达。 举一个更简单的例子,考虑: >>> i = int(

... '#',

... base=2

... )

...

----------------------------------------------------------------...

您面临的问题是$_POST['row_driver']不是数组。 如果您有一个隐藏的HTML输入:

...然后$_POST['row_driver']将是一个字符串,例如: $_POST['row_driver'] = "Array ( [0] => d1 [1] => d2 [2] => d3 [3] => d5 )";

因此,你的count()函...

使用命令模块,它将返回相同的结果。 import commands

commands.getstatusoutput('stat /fooDir')

I figured out the inode number was intended to be an unsigned long, but om.stat was interpreting as a negative number because the MSB was set. So now that I know its sup...

它可能是一个尾随的新行或空白 “\ n” 要么 “” ......试试...... if client_name.strip() == client_status.strip():

It could be a trailing new-line or whitespace "\n" or " " ... try... if client_name.strip() == client_status.strip():

相关文章

HDFS是一个分布式文件系统,然而对于程序员来说,HDFS就是一个普通文件系统,Hadoop进行的底层

...

Python 编程语言具有很高的灵活性,它支持多种编程方法,包括过程化的、面向对象的和函数式的。但最重

...

python2和python3的区别,1.性能 Py3.0运行 pystone benchmark的速

...

Python的文件类型 Python有三种文件类型,分别是源代码文件、字节码文件和优化代码文件

源代

...

python的官网:http://www.python.org/ 有两个版本,就像struts1和st

...

好久没有写了,还不是近期刚过的期末考试和期中考试 最近因为一个微信公众平台大赛在学phthon 找了本

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值