The documentation is available on ReadTheDocs

The module is available on PyPI and GitHub

Typical Usage for “File not found” Errors¶

If your code is unable to find a filename in the current working directory, you can print a “Did you mean %s?n” message by calling:

>>> import pydidyoumean >>> pydidyoumean . printFileSuggestion ( 'typo_filename.txt' ) Did you mean typo_filename.exe?

The default arguments for printFileSuggestion() are as follows:

>>> import pydidyoumean >>> pydidyoumean . printFileSuggestion ( 'typo_filename.txt' , message = 'Did you mean %s ?

' , folder = '.' , threshold = 2 , includeIdenticalFilename = False )

The %s in the message will be replaced by the suggested file. The threshold is the max Levenshtein edit distance (the number of character additions, removals, or replacements needed to convert one string into another). The printFileSuggestion() function compares the typo filename against all files and folders in folder . If there are multiple filenames tied for the lowest edit distance, it is undefined which one is returned.

You can get the string that printFileSuggestion() prints by calling formatFileSuggestion() , which has all the same arguments:

>>> import pydidyoumean >>> pydidyoumean . formatFileSuggestion ( 'typo_filename.txt' ) 'Did you mean typo_filename.exe?

'

(This naming is similar to the pprint module’s pprint() and pformat() conventions.)

suggestFile() will return a string of the filename that formatFileSuggestion() would use, rather than an error message string. It does not have a message parameter.