1

ccc私は、私を夢中にさせているPythonスクリプトを持っています。問題のあるコードは次のとおりです... ifステートメントのコードが実行されていません。誰かが理由を提案できますか?:

print("refresh_type is: " + refresh_type)

if (refresh_type == "update"):
    print("hello world")
    cmd = 'sudo svn %s --username %s --password %s  %s' % ('up', un, pw, working_path)
    print("command is: " + str(cmd))
elif(refresh_type == 'checkout' or refresh_type == 'co'):
    cmd = 'sudo svn %s --username %s --password %s  %s %s' % (refreshType, un, pw, rc_service_url, working_path)

print('username = ' + credentials['un'])
print('password = ' + credentials['pw'])
print("working path = " + working_path)

print ステートメントの出力は次のとおりです。

refresh_type is: 'update'
username = 'cccc'
password = 'vvvvv'
working path = '/home/ubuntu/workingcopy/rc_service'
4

1 に答える 1

4

あなたのrefresh_type価値はではなく update'update'です。残りの変数は同じ病気に苦しんでおり、文字列 value の一部として引用符を持っています。

print "refresh_type is:", repr(refresh_type)これを診断の補助として使用します。

あなたが使用することができます:

if refresh_type == "'update'":

ただし、文字列値に余分な引用符が含まれるという、より根本的な問題があります。

例として、短い Python インタープリター セッションを示します。

>>> print 'update'
update
>>> print "'update'"
'update'
>>> "'update'" == 'update'
False
>>> foo = "'update'"
>>> print repr(foo)
"'update'"
于 2013-01-01T00:45:40.867 に答える