module filehelper.visual_sync
¶
Short summary¶
module pyquickhelper.filehelper.visual_sync
Use jsdifflib to visualize the differences between two files.
Functions¶
function |
truncated documentation |
---|---|
The function uses jsdifflib to create a visual diff. If it was not already … |
|
Calls function |
Documentation¶
Use jsdifflib to visualize the differences between two files.
- pyquickhelper.filehelper.visual_sync.create_visual_diff_through_html(string1, string2, notebook=False, context_size=None, inline_view=False)[source]¶
The function uses jsdifflib to create a visual diff. If it was not already done, the function downloads the tool using pymyinstall.
- Parameters:
string1 – first string (anything such as an url, a file, a string, a stream)
string2 – second string (anything such as an url, a file, a string, a stream)
notebook – if True, the function assumes the outcome will be displayed from a notebook and does things accordingly, see below
context_size – to display everything (None) or just the changes > 0
inline_view – only for notebook, True: one column, False: two columns
- Returns:
html page or (HTML, Javascript) object if notebook is True
Visualize the difference between two text files or strings
with open("file1.txt","r",encoding="utf8") as f: text1 = f.read() with open("file2.txt","r",encoding="utf8") as f: text2 = f.read() pg = create_visual_diff_through_html(text1,text2) with open("page.html","w",encoding="utf8") as f: f.write(pg) import webbrowser webbrowser.open("page.html")
The function uses
read_content_ufs
to retrieve the content.
- pyquickhelper.filehelper.visual_sync.create_visual_diff_through_html_files(file1, file2, encoding='utf8', page=None, browser=False, notebook=False, context_size=None, inline_view=False)[source]¶
Calls function
create_visual_diff_through_html
with the content of two files.- Parameters:
file1 – first file (anything such as an url, a file, a string, a stream)
file2 – second file (anything such as an url, a file, a string, a stream)
encoding – encoding
page – if not None, saves the results in file
browser – open browser ?
notebook – if True, the function assumes the outcome will be displayed from a notebook and does things accordingly
context_size – to display everything (None) or just the changes > 0
inline_view – only for notebook, True: one column, False: two columns
- Returns:
html page or (HTML, Javascript) object if notebook is True
An example of the results is shown in blog post 2015-04-23 Visualize differences between two files in a notebook. The function now uses
read_content_ufs
to retrieve the content.Compares two files
The command calls function
create_visual_diff_through_html_files
and produces a HTML page with shows the differences between two files. Example:python -m pyquickhelper visual_diff -f <file1> -fi <file2> --browser=1 --page=diff.html
It works better with chrome.
<<<
python -m pyquickhelper visual_diff --help
>>>
usage: visual_diff [-h] [-f FILE1] [-fi FILE2] [-e ENCODING] [-p PAGE] [-b BROWSER] [-n NOTEBOOK] [-c CONTEXT_SIZE] [-i INLINE_VIEW] Calls function :func:`create_visual_diff_through_html <pyquickhelper.filehelper.visual_sync.create_visual_diff_through_html>` with the content of two files. optional arguments: -h, --help show this help message and exit -f FILE1, --file1 FILE1 first file (anything such as an url, a file, a string, a stream) (default: None) -fi FILE2, --file2 FILE2 second file (anything such as an url, a file, a string, a stream) (default: None) -e ENCODING, --encoding ENCODING encoding (default: utf8) -p PAGE, --page PAGE if not None, saves the results in file (default: ) -b BROWSER, --browser BROWSER open browser ? (default: False) -n NOTEBOOK, --notebook NOTEBOOK if True, the function assumes the outcome will be displayed from a notebook and does things accordingly (default: False) -c CONTEXT_SIZE, --context_size CONTEXT_SIZE to display everything (None) or just the changes > 0 (default: ) -i INLINE_VIEW, --inline_view INLINE_VIEW only for notebook, True: one column, False: two columns (default: False)