我在Datafactory中配置了一个管道。它有一个调用数据库记事本的活动。我想从Datafactory传递一个布尔值并将其读入数据库记事本,以便可以使用它来执行基于布尔值的条件。我从Datafactory传递了一个值为“False”的字符串类型的参数,并将其转换为布尔值。test_var = bool(dbutils.widgets.get(“bool_var”))如果我打印test_var,即使我传递了False,它也会打印为True。如何解决这一问题?我尝试将字符串转换为布尔值
3hvapo4f1#
当使用bool(dbutils.widgets.get("bool_var"))时,它将始终计算为True,因为字符串不为空要解决这个问题,可以显式检查字符串值并相应地将其转换为布尔值
bool(dbutils.widgets.get("bool_var"))
True
bool_var_str = dbutils.widgets.get("bool_var")# Convert the string to a Booleantest_var = bool_var_str.lower() == 'true'
bool_var_str = dbutils.widgets.get("bool_var")
# Convert the string to a Boolean
test_var = bool_var_str.lower() == 'true'
字符串此代码段显式检查字符串的XML版本是否为true,以确保正确转换为布尔值。当希望布尔值变量为False时,请确保从DataFactory传递False,当希望布尔值变量为True时,请确保从DataFactory传递True
true
False
1条答案
按热度按时间3hvapo4f1#
当使用
bool(dbutils.widgets.get("bool_var"))
时,它将始终计算为True
,因为字符串不为空要解决这个问题,可以显式检查字符串值并相应地将其转换为布尔值
字符串
此代码段显式检查字符串的XML版本是否为
true
,以确保正确转换为布尔值。当希望布尔值变量为False
时,请确保从DataFactory传递False
,当希望布尔值变量为True
时,请确保从DataFactory传递True