我是python的新手我正在尝试分配变量,它说语法错误
protocol = input.readLine()
connectUrlHttp='http'
connectUrlHttps='https'
if protocol== "t3s":
connectUrl=connectUrlHttps
elif protocol== "iiops":
connectUrl=connectUrlHttps
else:
connectUrl=connectUrlHttp
sca_deployComposite(connectUrl"://"+host+":"+port,emdroot+"/"+compositeLoc,owrite,user, password,default)
我面临以下错误
(no code object) at line 0
File "/scratch/agentHome/sdappaji2/core/12.1.0.3.0/EMStage/PAF/DeployCompositesDP1367835748253/deploycompositesscripts/deployComposites.py", line 36
connectUrl=connectUrlHttp
请指导我并给出一些指示
答案 0 :(得分:3)
在Python中,indentation级别很重要:
每个缩进级别使用4个空格。
- PEP 8 -- Style Guide for Python Code
您的代码应该如下所示:
protocol = input.readLine()
connectUrlHttp = 'http'
connectUrlHttps = 'https'
if protocol == "t3s":
connectUrl = connectUrlHttps
elif protocol == "iiops":
connectUrl = connectUrlHttps
else:
connectUrl = connectUrlHttp
# Note the `+` after `connectUrl` on the next line:
sca_deployComposite(connectUrl + "://" + host + ":" + port, emdroot + "/" +
compositeLoc, owrite, user, password, default)
答案 1 :(得分:1)
实际的语法错误在这里:
sca_deployComposite(connectUrl"://"+host+":"+port,emdroot+"/"+compositeLoc,owrite,user, password,default)
^^^
你可能错过了+
那里。
Ashwini指出,else
之后的缩进也是错误的。
答案 2 :(得分:1)
else:
if protocol== "t3s":
connectUrl=connectUrlHttps
elif protocol== "iiops":
connectUrl=connectUrlHttps
else:
connectUrl=connectUrlHttp
sca_deployComposite(connectUrl+"://"+host+":"+port,emdroot+"/"+compositeLoc,owrite,user, password,default)
另外,您在+
之后错过了sca_deployComposite(connectUrl
。