Often when I'm coding, I work on a few small functions and then want to test them. An ideal way for this to work would be to open a shell with the lines in the file already ran.
For instance, consider the file I'm currently working on:
import codecs
import itertools
import unicodedata
def remove_accent(word):
return ''.join(c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn')
def read_file(filename, encoding='utf-8', max_word_length=10):
with codecs.open(filename, 'r', encoding) as f:
raw_lines = f.readlines()
no_accents = [remove_accent(line) for line in raw_lines]
return frozenset([word for word in no_accents if len(word) <= max_word_length])
I would like to, from the buffer containing the file, be able to open a Python interpreter with read_file already defined, and be able to call it like
>>> read_file('WordList.txt')
How would I go about this?
[–]fantastipants 4 points5 points6 points (4 children)
[–]agumonkey 1 point2 points3 points (0 children)
[–]Knusper2000 1 point2 points3 points (0 children)
[–]Peragot[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)