如何在Web浏览器中本地运行(.py)Python文件?

时间:2018-12-08 02:13:50

标签: python python-3.x

是否可以在不运行Web服务器的情况下在Web浏览器上本地运行(.py)Python文件?也不使用外部服务。因此,如果无法使用互联网,该文件仍将在浏览器中运行。我想在Chrome或IE的电脑上运行此代码。谢谢。

def concept(phrase):

# split var(phrase) at spaces and assign to var(words)
words = phrase.split()

# use this to list python file titles and links to open them
files    = {1:"file0001.txt",
            2:"file0002.txt",
            3:"file0003.txt",
            4:"file0004.txt",
            5:"file0005.txt",
            6:"file0006.txt",
            7:"file0007.txt",    
            8:"file0008.txt",
            9:"file0009.txt"}

# change keys to searchable simple keyword phrases. 
concepts = {'GAMES':[1,2,4,3,3],
            'BLACKJACK':[5,3,5,3,5],
            'MACHINE':[4,9,9,9,4],
            'DATABASE':[5,3,3,3,5],
            'LEARNING':[4,9,4,9,4]}

# iterate through all var(words) found in var(word)
for word in words:
# convert to uppercase, search var(word) in dict 'concepts', if not found return not found"
    if word.upper() not in concepts:
        print("'{}':Not Found in Database \n" .format(word)) not in concepts
    else:
# for matching keys in dict 'concept' list values in dict 'files'
        for pattern in concepts[word.upper()]:
            print(files[pattern])

# return input box at end of query        
while True:
     concept(input("Enter Concept Idea: "))   

1 个答案:

答案 0 :(得分:0)

您可以通过http://localhost:8889/lab

安装JupyterLab并在网络浏览器中运行python项目

更简单的方法:

我安装了anaconda导航器,其中包括JupyterLab和其他方便的功能,例如python版本控制和程序包控制。