2013-05-06 82 views
0

我新的Python我想分配變量,它說systax錯誤而分配變量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 

請指引我,給一些指針

回答

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

實際的語法錯誤是在這裏:

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

您可能在那裏錯過了+。正如Ashwini指出的那樣,

else之後的縮進也是錯誤的。

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+