I have script like:
from string import digits, uppercase, lowercase, punctuation
from itertools import product
chars = lowercase + uppercase + digits + punctuation
for n in range(1, 2+1):
for comb in product(chars, repeat=n):
print ''.join(comb)
it works fine. Imagine chars is giving by an external user so:
import sys
from string import digits, uppercase, lowercase, punctuation
from itertools import product
chars = sys.argv[1] # sys.argv[1] is 'lowercase+uppercase+digits+punctuation'
for n in range(1, 2+1):
for comb in product(chars, repeat=n):
print ''.join(comb)
when run script.py: It has not the result when you say:
chars = lowercase + uppercase + digits + punctuation
Now how can I get the previous result?
chars = 'lowercase+uppercase+digits+punctuation'the program doen't work. because lowercase and etc are functions not string... how can the the python these are not string and thy are functionsstringwith those names, you must tell Python as much. Trivial research will tell you how.string.lowercase == getattr(string, 'lowercase')assuming that you have importedstring