NameError:name' permutations'没有定义

时间:2018-04-28 15:35:50

标签: python nameerror

这是一个生成密码字典以猜测密码的脚本。

我收到此错误:

Traceback (most recent call last):

File "pass.py", line 19, in <module>
  for p in permutations(stuff, x):
     NameError: name 'permutations' is not defined

代码:

#!/usr/bin/python

# define the prefix to try since we knew what the password starts with
prefix = ['begin', 'Begin']

# list of sequences to run through
sequences = ['seq1', 'Seq1', 'SEQ1', 'se2', '!', '123', '555', '103', '_']

# open the password file where the dictionary will be saved

newfile = open('mypass.txt', 'w')

# A python3 thing I guess
stuff = list(sequences)

# Generate permutations of the password, starting wth the prefix and then 2 to 6 combos of the "charset"
for i in prefix:
  for x in range(2,6):
    for p in permutations(stuff, x):
        newfile.write(''.join(p) + '\n')

示例输出:

beginseq1SEQ1
begin_seq1
Begin_seq1103

1 个答案:

答案 0 :(得分:-1)

permutations可能是来自其他文件或包的函数。可能你是一个新的python用户,忘记在你的代码顶部说明你引用的文件或包。如果从文件导入,则必须添加如下所示的行:

from some_code_file.py import some_function

或者像这样,如果你导入一个包:

import python_package as py_pa

而且你的代码应该像你写的一样工作。或者只是更改为some_function.permutations(stuff,x)py_pa.permtations(stuff,x)

表单