Generating Wordlist, Python Script -


this first post in stack overflow , new python(this not code, found in programming magazine).

#!/usr/bin/env python #letter_changer.py dr@g import sys def replace_chars(line,dic_words):  i,j in dic_words.iteritems():   line=line.replace(i,j)  return line letters={‘8’:’th’,’3’:’ks’,’4’:’ps’} f=sys.argv[1] filename=open(f,’r’) line in filename:  new_line=replace_chars(line,letters)  print new_line, filename.close() 

this script used enrich wordlist, supposed read string, change letter another(line 8) , create new entry string. each line of dictionary contains 1 entry in each line. after running script got following error:

syntaxerror: non-ascii character ‘\xe2′ in file letter_changer.py on line 8, no encoding declared; see http://www.python.org/peps/pep-0263.html details

after research on internet realized should use piece of code @ beginning of script:

# vim: set fileencoding=utf-8 : 

(but don't understand why, since used english characters)

after fixing had problem on line 8: letters={‘8’:’th’,’3’:’ks’,’4’:’ps’}

file “letter_changer.py”, line 8 letters=letters.replace(‘8’:’th’,’3’:’ks’,’4’:’ps’) ^ syntaxerror: invalid syntax

the solution might simple new in python, reply useful, tips , general guidelines

thank in advance

it's not question of english characters, question of ascii , quote characters. file contains non-ascii quote characters on lines 8 , 10, because not ascii quote characters, if tell python file utf-8, still won't recognize things strings. compare:

“smart” quotes:

letters={‘8’:’th’,’3’:’ks’,’4’:’ps’} f=sys.argv[1] filename=open(f,’r’) 

ascii quotes:

letters={'8':'th','3':'ks','4':'ps'} f=sys.argv[1] filename=open(f,'r') 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -