简体   繁体   English

分配变量时发生Python语法错误

[英]Python syntax error while assigning variable

I am new to python I am trying to assign variable it says systax error 我是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)

I am facing below error 我面临以下错误

(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

Please guide me and give some pointers 请指导我,并给我一些指导

In Python, indentation levels are significant: 在Python中, 缩进级别很重要:

Use 4 spaces per indentation level. 每个缩进级别使用4个空格。

-- PEP 8 -- Style Guide for Python Code -PEP 8-Python代码样式指南

Your code should probably look like this: 您的代码应该看起来像这样:

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)

The actual syntax error is here: 实际的语法错误在这里:

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

You probably missed a + there. 您可能错过了+

The indentation is also wrong after the else , as Ashwini points out. 正如Ashwini指出的那样,缩进在else后面也是错误的。

Your code is not properly indented after else: else:您的代码未正确缩进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)

Plus you were missing a + after sca_deployComposite(connectUrl . 另外,您在sca_deployComposite(connectUrl之后,缺少了一个+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM