检查python中变量的状态

时间:2017-02-24 17:56:05

标签: python python-2.7 python-3.x

我正在尝试使用if语句进行审核,但播放列表中包含单词' http',playlist should have value 'http: //*********/****.m3u但是如果播放列表不包含单词' http'那么我想得到值playlist '"file: ///" + playlist'

def GETPLAYLIST(): 
    playlistset = int(addon.getSetting('playlistset')) + 1 
    playlist = addon.getSetting('playlist' + str(playlistset)) 
    if 'http' in 'playlist'
    else:
        playlistlist = "file:///" + playlist
    return playlist

1 个答案:

答案 0 :(得分:0)

你可以改变你的状况并这样做:

def GETPLAYLIST(): 
    playlistset = int(addon.getSetting('playlistset')) + 1 
    playlist = addon.getSetting('playlist' + str(playlistset)) 
    if not 'http' in playlist:
        playlist = "file:///" + playlist
    return playlist