当前位置: 动力学知识库 > 问答 > 编程问答 >

How to "try" a python program

问题描述:

and sorry for this question. I'm a Ruby developer and I have no knowledge of Python. Now I must write a parser plugin for a Kodi Media Center add-on and the parser is written in python.

I have several example to follow and also a guide so I can write something, the problem is that I want to try my parser on my computer instead of loading it on my Kodi Media Center.

I have a .py file with some function inside like this:

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

It's similar to ruby so I can read it and I think I can also rewrite it, but I need to know how can I "launch" this file on OSX adding some debug lines to check if everything is ok before creating the add on package.

In ruby I can use ruby filename and I can add some pry and some puts, but with Python I have no idea.

网友答案:

To run a python program you can do:

python filename.py

And to print a variable:

print(variable)
网友答案:

Well probably using python is really easy indeed.

To print a variable in python:

print(variable)

Then to execute the program:

python filename.py

If you're a windows user in some cases it would work as the following:

py filename.py
分享给朋友:
您可能感兴趣的文章:
随机阅读: