0

我是 python 新手,我正在尝试分配变量,它说 systax 错误

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

请指导我并给出一些指示

4

3 回答 3

3

在 Python 中,缩进级别很重要:

每个缩进级别使用 4 个空格。

-- PEP 8 -- Python 代码风格指南

您的代码应该如下所示:

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)
于 2013-05-06T10:38:33.363 回答
1

实际的语法错误在这里:

sca_deployComposite(connectUrl"://"+host+":"+port,emdroot+"/"+compositeLoc,owrite,user, password,default)
                            ^^^

你可能错过了+那里。

else正如 Ashwini 指出的那样,之后的缩进也是错误的。

于 2013-05-06T10:36:17.433 回答
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)

再加上你错过了+after sca_deployComposite(connectUrl

于 2013-05-06T10:36:48.230 回答