I have a function that checks if a file exists, it returns 'True'
/'False'
, right now I'm 'converting' it to bool with eval()
, however I don't think this is the smartest solution, but I'm not sure how else to do it without unnecessary ifs
,
>>> foo = 'False'
>>> type(eval(foo))
<class 'bool'>
>>> type(foo)
<class 'str'>
For example, I'm running this expression, on ssh connected machine
"test -e {0} && echo True || echo False".format(self.repo)
like this, and my result is going to be string.
def execute(command):
(_, stdOut, _) = ssh.exec_command(command)
output = stdOut.read()
return output.decode('utf-8')
Is there any other way to achieve this?