Home > Back-end >  How can I get the len of nontype
How can I get the len of nontype

Time:11-08

Hello guys I'm trying to write a program that generate a random password then cracks is it but I'm getting the error object of type 'NoneType' has no len()

from random import choice
from string import ascii_lowercase 

def nrndprint(n):
  k=(''.join(choice(ascii_lowercase) for i in range(n)))  #.join
  print(k)
nrndprint(6)
import itertools
def crack_pass(argpass):
  alplist = list(map(chr,list(range(ord('a'),ord('z') 1))))
  for combi in itertools.product(alplist,repeat=len(argpass)):
    if "".join(combi)==argpass:
      return combi
  return '-1'
passwd = nrndprint(4)
print(passwd)
print(crack_pass(passwd))

I'm getting:

#mqjz
#None

Expected:

#mqjz
#('m','q','j','z')

CodePudding user response:

You can't calculate the length of NoneType.

Your function nrndprint() doesn't return anything. Adding return k will solve your problem.

CodePudding user response:

NoneType doesn't have len() method so it's raising an error.

You are assinging passwd = nrndprint(4) and then passing the passwd variable to crack_pass, but since your function nrndprint doesn't return anything, variable passwd will be None. You can fix it by making nrndprint function return a value.

  • Related