pip install termcolor cprint() 功能相当于print(colored(something))。 cprint('sometext','color','on_color',attrs=[]) 其中: color:文字颜色。可选,grey,red,green,yellow,blue,magenta,cyan,white。 on_color:背景色,可选,on_grey,on_red,on_green,on_yellow,on_blue,on_magenta,on_cyan,on_white。
color_info = "[\033[1;36m Info \033[0m]" ## 青蓝色 Info user_file="text.txt" print(f"\n{color_err} 请检查 %s 文件是否存在 或 拼写是否正确!!!\n" % user_file ) print(f"\n{color_ok} 请检查 %s 文件是否存在 或 拼写是否正确!!!\n" % user_file ) print(f"\n{color_war}...
def set_cmd_text_color(color, handle=std_out_handle): Bool = ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color) return Bool # get handle std_out_handle = ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) def set_cmd_text_color(color, handle=std_out_handle): Bool = ctypes...
def set_cmd_text_color(color, handle=std_out_handle): Bool = ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color) return Bool #reset white def resetColor(): set_cmd_text_color(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) #green def printGreen(mess): set_cmd_text_color(FOR...
3. Print color text using ANSI code in Python You can use ANSI code style to make your text more readable and creative. You can use ANSIescape codesto change the color of the text output in thePython programs. A good use case for this is tohighlight errors. The escape codes are enter...
You can change your text tobold,italic, andunderlinedin Python. Not only can you play around with the style of your code but also change its color with the help of specific packages and modules in Python. Interesting! Isn’t it?
print(soup.title.string) print(soup.find('meta', attrs={'property':'og:deion'})) # Extract anchor tag value forxinsoup.find_all('a'): print(x.string) # Extract Paragraph tag value forxinsoup.find_all('p'): print(x.text)
After outputting the last line, the terminal will be reset back to its default color because ofbcolors.RESET. If you fail to put it at the end of your lines, the text within the terminal will be colored the last color you set withinprint(). In this case, it would be red. ...
(y_test_actual,y_predict) plt.plot([np.min(y_test_actual), np.max(y_test_actual)], [np.min(y_test_actual), np.max(y_test_actual)], color='lightblue') plt.xlabel("Actual Fare Amount") plt.ylabel("Predicted Fare Amount") plt.title("Actual vs Predicted Fare Amount R^2={}"...
[128,128,128]]# 找到最近的颜色deffind_closest_color(pixel):returnmin(palette,key=lambdacolor:np.linalg.norm(np.array(color)-np.array(pixel)))# 处理图像数组colorized_array=np.array([[find_closest_color(tuple(pixel))forpixelinrow]forrowinimg_array])# 返回颜色化的图像returnImage.fromarray(...