File tree 2 files changed +20
-3
lines changed
2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 6
6
"get_full_data_path" ,
7
7
"get_pythainlp_data_path" ,
8
8
"get_pythainlp_path" ,
9
+ "safe_print" ,
9
10
"warn_deprecation" ,
10
11
]
11
12
12
- from pythainlp .tools .core import warn_deprecation
13
+ from pythainlp .tools .core import safe_print , warn_deprecation
13
14
from pythainlp .tools .path import (
14
15
PYTHAINLP_DEFAULT_DATA_DIR ,
15
16
get_full_data_path ,
Original file line number Diff line number Diff line change 5
5
Generic support functions for PyThaiNLP.
6
6
"""
7
7
8
+ import sys
8
9
import warnings
9
10
10
11
@@ -13,8 +14,7 @@ def warn_deprecation(
13
14
replacing_func : str = "" ,
14
15
version : str = "" ,
15
16
):
16
- """
17
- Warn about the deprecation of a function.
17
+ """Warn about the deprecation of a function.
18
18
19
19
:param str deprecated_func: Name of the deprecated function.
20
20
:param str replacing_func: Name of the function to use instead (optional).
@@ -28,3 +28,19 @@ def warn_deprecation(
28
28
if replacing_func :
29
29
message += f" Please use '{ replacing_func } ' instead."
30
30
warnings .warn (message , DeprecationWarning , stacklevel = 2 )
31
+
32
+
33
+ def safe_print (text : str ):
34
+ """Print text to console, handling UnicodeEncodeError.
35
+
36
+ :param text: Text to print.
37
+ :type text: str
38
+ """
39
+ try :
40
+ print (text )
41
+ except UnicodeEncodeError :
42
+ print (
43
+ text .encode (sys .stdout .encoding , errors = "replace" ).decode (
44
+ sys .stdout .encoding
45
+ )
46
+ )
You can’t perform that action at this time.
0 commit comments