Jython:SyntaxError:第29行第32列的词法错误。遇到:" $" (36),之后:""

时间:2016-10-19 10:07:30

标签: python jython

我的代码中出现语法错误。任何人都可以说语法中的错误是什么?我是这种语言的新手,没有太多想法。

错误讯息:

WASX7017E:运行文件时收到异常" jdbcConn.jy&#34 ;;异常信息:com.ibm.bsf.BSFException:来自Jython的异常:Traceback(最里面的最后一个):(没有代码对象)第0行文件"",第29行classpath = [" classpath&# 34; ,$ {ORACLE_JDBC_DRIVER_PATH} /ojdbc6.jar] ^ SyntaxError:第29行第32列的词法错误。遇到:" $" (36),之后:""

我的代码:

import sys

## **JDBCProvider** ##

def OracleJDBC(cellName,serverName):
    name ="Oracle JDBC Driver"
    print " Name of JDBC Provider which will be created ---> " + name
    print "   ----------------------------------------------------------------------------------------- "
    # Gets the name of cell
    cell = AdminControl.getCell() 
    print cell
    cellid = AdminConfig.getid('/Cell:'+ cell +'/')
    print cellid
    print "   ----------------------------------------------------------------------------------------- "
    ## Creating New JDBC Provider ##
    print " Creating New JDBC Provider :"+ name 
    n1 = ["name" , "Oracle JDBC Driver" ]
    desc = ["description" , "Oracle JDBC Driver"]
    impn = ["implementationClassName" ,
            "oracle.jdbc.pool.OracleConnectionPoolDataSource"]
    classpath = ["classpath" , ${ORACLE_JDBC_DRIVER_PATH}/ojdbc6.jar ]
    attrs1 = [n1 , impn , desc , classpath]

    n1 = ["name" , "Oracle JDBC Driver" ]

    desc = ["description" , "Oracle JDBC Driver"]

    impn = ["implementationClassName" , "oracle.jdbc.pool.OracleConnectionPoolDataSource"]

    classpath = ["classpath" , "${ORACLE_JDBC_DRIVER_PATH}/ojdbc6.jar"]

    attrs1 = [n1 , impn , desc , classpath]

    Serverid = AdminConfig.getid("/Cell:" + cellName + "/ServerName:" + serverName +"/")

    jdbc = AdminConfig.create('JDBCProvider', Serverid, attrs1)

    print " New JDBC Provider created :" + name 

    AdminConfig.save()

    print " Saving Configuraion " 

    print "   ----------------------------------------------------------------------------------------- "

    ####################################################################################################################
    ####################################################################################################################

#main program starts here
if __name__ == '__main__':
    cellName = sys.argv[0]
    serverName = sys.argv[1]
    OracleJDBC(cellName,serverName)

2 个答案:

答案 0 :(得分:2)

你的问题在这一行:

classpath = ["classpath" , ${ORACLE_JDBC_DRIVER_PATH}/ojdbc6.jar ]

相反,做一些像

这样的事情
opath = os.getenv("ORACLE_JDBC_DRIVER_PATH")
classpath = ["classpath", "{}/ojdbc6.jar".format(opath)]

" $ {ORACLE_JDBC_DRIVER_PATH}"是shell语法,而不是Python。

答案 1 :(得分:0)

更改此行

classpath = ["classpath" , ${ORACLE_JDBC_DRIVER_PATH}/ojdbc6.jar ]

到此:

classpath = ["classpath" , "${ORACLE_JDBC_DRIVER_PATH}/ojdbc6.jar" ]

或更好,只需删除该行。无论如何,classpath稍后再次声明为相同的值