Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在windows上的CMD上运行python程序时遇到问题_Python_Windows_Python 3.x_Cmd - Fatal编程技术网

在windows上的CMD上运行python程序时遇到问题

在windows上的CMD上运行python程序时遇到问题,python,windows,python-3.x,cmd,Python,Windows,Python 3.x,Cmd,这是节目单。它在空闲时工作得很好,但在询问您是否知道密码长度后崩溃。我似乎想不出我错过了什么。我愿意得到任何帮助 import itertools import string import sys, os, cmd from datetime import datetime FMT = '%Y-%m-%d %H:%M:%S' passwordstried = 0 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0,] #symbols = [ lowercase

这是节目单。它在空闲时工作得很好,但在询问您是否知道密码长度后崩溃。我似乎想不出我错过了什么。我愿意得到任何帮助

import itertools
import string
import sys, os, cmd

from datetime import datetime
FMT = '%Y-%m-%d %H:%M:%S'
passwordstried = 0


numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0,]
#symbols = [
lowercaseletters =  ["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","g","h","j","k","l","z","x","c","v","b","n","m"]
uppercaseletters = ["Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","G","H","J","K","L","Z","X","C","V","B","N","M"]


stuff = lowercaseletters + uppercaseletters + numbers

if (input("Do you have the length of the password?") == 'y'):
    lengthstartingvalue = int(input("Password length: "))
else:
    lengthstartingvalue = 0


starttime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(starttime)





starttime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
for L in range(lengthstartingvalue, len(stuff)+1):
    for subset in itertools.combinations_with_replacement(stuff, L):
        print(subset)
        passwordstried = passwordstried + 1
    if (L>lengthstartingvalue-1):
        break

endtime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
elapsed = datetime.strptime(endtime, FMT) - datetime.strptime(starttime, FMT)
print ('Time elapsed:',elapsed)
print ('Passwords tried:',passwordstried)

@275365是对的,你应该使用

if(原始输入(“您有密码的长度吗?”)==“y”):

而不是

if(输入(“您有密码的长度吗?”)==“y”):

使用
input()
会导致崩溃

In [11]: run tt.py
Do you have the length of the password?y
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
C:\Program Files (x86)\ipython-0.12.1\IPython\utils\py3compat.py in execfile(fname, glob, loc)
    166             else:
    167                 filename = fname
--> 168             exec compile(scripttext, filename, 'exec') in glob, loc
    169     else:
    170         def execfile(fname, *where):

D:\Users\sp\Desktop\tt.py in <module>()
     16 stuff = lowercaseletters + uppercaseletters + numbers
     17
---> 18 if (input("Do you have the length of the password?") == 'y'):
     19     lengthstartingvalue = int(input("Password length: "))
     20 else:

D:\Users\sp\Desktop\<string> in <module>()

NameError: name 'y' is not defined
[11]中的
:运行tt.py
你有密码的长度吗
---------------------------------------------------------------------------
NameError回溯(最近一次呼叫上次)
C:\ProgramFiles(x86)\ipython-0.12.1\ipython\utils\py3compat.py在execfile(fname、glob、loc)中
166.其他:
167 filename=fname
-->168 exec编译(脚本文本,文件名,'exec'),在glob,loc中
169其他:
170 def execfile(fname,*其中):
D:\Users\sp\Desktop\tt.py in()
16 stuff=小写字母+大写字母+数字
十七,
--->18如果(输入(“您有密码的长度吗?”)==“y”):
19 lengthstartingvalue=int(输入(“密码长度:”)
20其他:
D:\Users\sp\Desktop\in()
名称错误:未定义名称“y”

将其更改为
raw\u input()
运行到完成时不会发生崩溃。

看起来您运行的IDLE版本可能与您正在编码的版本不同。如果我理解正确,raw_input()在CMD上工作,但在IDLE中中断,而input()在IDLE中工作,在CMD中中断。您可能需要下载适用于Python3的IDLE的正确版本,或者如果您已经下载了IDLE,那么您只是在访问适用于Python2的IDLE

否则,Windows中的Path变量可能会出现问题。在系统->高级系统设置->环境变量->路径-中,需要将其设置为Python 3.3安装


在我看来,您的路径可能仍然停留在以前的安装上。

它是如何崩溃的?你能发布例外情况吗?就是这样。我甚至看不出发生了什么。你能提供更多的信息吗?追踪?看起来您正在使用Python3.x。问题是窗户消失了吗?如果是这样,只需添加
input()
作为最后一条语句,这样窗口就会一直打开,直到您点击@Conner。您能澄清您使用的是哪一版本的Python吗?@Levon感谢您的慷慨,但您的回答很好+OP声称正在使用Python 3.3。除非OP没有意识到多个Python版本有问题(可能是这样),否则这不是答案。使用print()表示我使用的是3.3,我刚刚卸载了2.7,以确保不是这样。@Conner如果将
input()
更改为
raw\u input()
,会发生什么?我在3.2.3(我现在唯一可以访问的3.x版本)下运行了这个没有崩溃的程序。