我是Jython的新手。我试图通过Java程序(使用Jython)执行python脚本。在python脚本中,我试图调用一些外部库(称为petl)的方法。当我尝试使用python(As:python script.py)执行脚本时,它执行没有任何问题。但是当我尝试使用Jython(As:jython script.py)访问脚本时,它会给我以下错误。
P.S:我可以毫无问题地运行简单的python脚本。但是当我尝试通过脚本访问外部库函数时,它会给我一个错误。
任何人都可以给我一个解决方法或一些建议吗?提前谢谢。
Python脚本:
import petl as etl
table1 = etl.fromcsv('Books.csv')
table2 = etl.sort(table1, 'ACCOUNT_ID')
etl.tocsv(table2, source='NewBooks.csv',encoding='utf-8')
错误堆栈:
Traceback (most recent call last):
File "test1.py", line 5, in <module>
etl.tocsv(table2, source='NewBooks.csv',encoding='utf-8')
File "C:\Jython\Lib\site-packages\petl\io\csv.py", line 106, in tocsv
tocsv_impl(table, source=source, encoding=encoding, errors=errors,
File "C:\Jython\Lib\site-packages\petl\io\csv_py2.py", line 50, in tocsv_impl
_writecsv(table, source=source, mode='wb', **kwargs)
File "C:\Jython\Lib\site-packages\petl\io\csv_py2.py", line 74, in _writecsv
for row in rows:
File "C:\Jython\Lib\site-packages\petl\transform\sorts.py", line 271, in _iter
nocache
hdr = next(it)
File "C:\Jython\Lib\site-packages\petl\io\csv_py2.py", line 30, in __iter__
codec = getcodec(self.encoding)
File "C:\Jython\Lib\site-packages\petl\io\base.py", line 12, in getcodec
codec = codecs.lookup(encoding)
at org.python.core.codecs.normalizestring(codecs.java:62)
at org.python.core.codecs.access$200(codecs.java:29)
at org.python.core.codecs$CodecState.lookup(codecs.java:1695)
at org.python.core.codecs.lookup(codecs.java:58)
at org.python.modules._codecs.lookup(_codecs.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
java.lang.NullPointerException: java.lang.NullPointerException
答案 0 :(得分:1)
在调用fromcsv()和tocsv()函数时,必须显式传递编码值。
mysql> SHOW FULL PROCESSLIST;
+-----+------------------+-----------------+---------+---------+------+--------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------------------+-----------------+---------+---------+------+--------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 253 | whitewall | localhost:39377 | mailing | Query | 4 | Sending data |
SELECT
contacts.ID,
contacts.RATING,
mails.MANDRILL_ID
FROM contacts
LEFT JOIN mails
ON mails.CONTACT_ID = contacts.ID
HAVING mails.MANDRILL_ID = 'fea4b3b036b44655a7e24121ac359d0a' |