2015-02-10 87 views
-4

并对此问题感到抱歉。我是一名Ruby开发人员,我不了解Python。现在我必须为Kodi Media Center插件编写解析器插件,解析器用python编写。如何“尝试”python程序

我有几个例子要遵循,也是一个指导,所以我可以写点东西,问题是我想在我的计算机上尝试我的解析器,而不是将其加载到我的Kodi媒体中心。

我有一些函数内像这样的.py文件:

def get_events(): 
    try: 
     source = mechanize_browser(base_url) 
    except: source = ""; xbmcgui.Dialog().ok(translate(40000),translate(40128)) 
    if source: 
     items = re.findall('<div class="base custom" align="center"(.*?)</center></div><br></div>', source, re.DOTALL) 
     number_of_items= len(items) 
     for item in reversed(items): 
      data = re.compile('<div style="text-align: center;">(.+?)</div>').findall(item) 
      try: 
       check = re.compile(" (.+?):(.+?)").findall(data[-1].replace("color:","")) 
       if not check and "Online" not in data[-1]:pass 
       else: 
        data_item = data[-1].replace("<strong>","").replace("</strong>","").replace('<span style="color: #008000;">','').replace("</span>","") 
        url = re.compile('<a href="(.+?)">').findall(item) 
        teams = re.compile('/.+?-(.+?).html').findall(url[0]) 
        try: 
               match = re.compile('(.+?) (.+?) (.+?):(.*)').findall(data_item) 
               import datetime 
               from utils import pytzimp 
               timezona= settings.getSetting('timezone_new') 
               d = pytzimp.timezone(str(pytzimp.timezone('Europe/Moscow'))).localize(datetime.datetime(2014, 6, int(match[0][0]), hour=int(match[0][2]), minute=int(match[0][3]))) 
               my_place=pytzimp.timezone(pytzimp.all_timezones[int(timezona)]) 
               convertido=d.astimezone(my_place) 
               fmt = "%d %H:%M" 
               time=convertido.strftime(fmt) 
               addDir("[B][COLOR orange]("+translate(600012)+time+")[/COLOR][/B] "+teams[0],url[0],401,os.path.join(current_dir,'icon.png'),number_of_items,True,parser="liveevent",parserfunction="streams") 
        except: 
         if '<span style="color: #000000;">' not in data_item: 
          addDir("[B][COLOR green]("+data_item+")[/COLOR][/B] "+teams[0],url[0],401,os.path.join(current_dir,'icon.png'),number_of_items,True,parser="liveevents",parserfunction="streams") 
         else: pass 
      except: pass 

它类似红宝石,所以我可以读它,我想我也可以重写,但我需要知道我怎么能在OSX上“启动”这个文件,在创建附加软件包之前添加一些调试行来检查是否一切正常。

在红宝石我可以使用ruby filename,我可以添加一些pry和一些puts,但与Python我不知道。

+0

我不假设你想过尝试'python filename'? – David 2015-02-10 08:26:56

+2

它应该比谷歌“python打印”更快写入所有这一切。基本上用'python filename'开始并使用'print'进行...打印。 – runDOSrun 2015-02-10 08:26:59

回答

0

要运行一个Python程序,你可以这样做:

python filename.py 

并打印变量:

print(variable) 
0

那么可能正在使用Python是很容易的确实。

在Python打印变量:如果你是一个Windows用户在某些情况下,它会工作为以下

python filename.py 

print(variable) 

然后执行程序

py filename.py 
+1

“我怎么能”在OSX上启动这个文件意味着他们不是Windows用户。 – PaulMcG 2015-02-10 18:57:06