PowerShell不会运行Python脚本

2024-10-02 14:30:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我在试着制作一个神秘的圣诞Python脚本。我有一个运行Ubuntu的虚拟机,我在里面运行脚本,没有问题。下一步,我想在PowerShell中运行它。我安装了Python,版本2.7.10(检查了vis PowerShell)。我以前在PowerShell中运行过其他脚本(甚至这个脚本的不同版本),所以我知道我已经正确地设置了这些脚本。但由于某种原因,这个不会运行。我甚至把print语句作为import后面的第一个实数行,但是它没有到达。我用的不是Windows内置的功能吗?在

import random
import pprint

people = ["Billy", "Joe", "Bob", "Sam", "John", "Kyle"]
chosen = {}
preventions = [["Joe", "Bob"], ["Sam", "John"]]

print "Test"
for person in people:
    groupExists = False
    for preventionGroup in preventions:
        if person in preventionGroup:
            groupExists = True

    if not groupExists:
        preventions.append([person])

for preventionGroup in preventions:
    for person in preventionGroup:
        while True:
            # print "Hi"
            num = random.randrange(0,6)
            # print num
            giftee = people[num]

            if giftee not in preventionGroup and giftee not in list(chosen.values()):
                chosen[person] = giftee
                break

# pprint.pprint(chosen)
for key, value in chosen.iteritems():
    print "Gifter: " + key
    raw_input()
    print "Giftee: " + value
    raw_input()

它名为Secret Santa.py,因此运行脚本的PowerShell行是

^{pr2}$

是的,我已经检查过确保我和文件在同一个目录中。在


Tags: inimport脚本forifpeoplepersonpprint