2012-05-20 15 views
0

这是我的。我得到'])'的语法错误,我不明白为什么?pyrss2gen,语法错误

import datetime 
import PyRSS2Gen 

jp = "Mokuyoubi" 
en = "Thursday" 

rss = PyRSS2Gen.RSS2(
    title = "Vocab of the Day - JapLearn.com", 
    link = "http://www.JapLearn.com", 
    description = "The latest JapLearn.com" 
        "Vocab of the Day!", 

    lastBuildDate = datetime.datetime.utcnow(), 

    items = [ 
     PyRSS2Gen.RSSItem(
     title = "Vocab of the Day - Date", 
     link = "http://www.JapLearn.com", 
     description = " Japanese: "+jp+ 
         "Translation: "+en, 
     pubDate = datetime.datetime() 
    ]) 

rss.write_xml(open("japlearn-votd.xml", "w")) 

回答

2
items = [ 
     PyRSS2Gen.RSSItem(
     title = "Vocab of the Day - Date", 
     link = "http://www.JapLearn.com", 
     description = " Japanese: "+jp+ 
         "Translation: "+en, 
     pubDate = datetime.datetime() 
    )] 

关闭(括号第一个而不是关闭[

由于@levon建议这些东西应该由您的editor处理。我个人使用Vim与syntastic进行自动语法检查。

您还需要提供适当的参数给pudate = datetime.datetime()。看看here给出的例子。

你的代码在执行时给了我这个错误。

File "rss.py", line 22, in <module> 
    pubDate = datetime.datetime(), 
TypeError: Required argument 'year' (pos 1) not found 
3

有两个问题与发布代码:

  1. 有一个失踪相应的右括号此 声明

    RSS = PyRSS2Gen.RSS2(

  2. 在另外@RanRag指出,你的])就在的下方开始pubDate必须逆转)]

我会建议使用符合括号(我使用emacs)和一些工具,如pylint的,pychecker等编辑器...帮助这些类型的问题。

+0

@abkai ..对于rss ='语句缺少相应的')'没有问题吗? – Levon