2

Is there a way to do this in python?:

def exist(path_image):
    if path.isfile(path_image):
       return path_image
    else:
       return False

path_image = '/home/user/image.jpg'
if (image = exist(path_image)):
   print(image)

Other languages like PHP and Javascript, I can initialize a variable inside 'IF'

Thanks

joserick
  • 327
  • 3
  • 11

1 Answers1

1

No, you cannot do this in Python. A simple alternative would be:

image = exist('/home/user/image.jpg')
if (image):
   print(image)
omni
  • 580
  • 1
  • 6
  • 16