How to filter only printable characters in a file on Bash (linux) or Python?

前端 未结 4 1003
挽巷
挽巷 2021-01-18 23:45

I want to make a file including non-printable characters to just only include printable characters. I think this problem is related to ACSCII control action, but I could not

4条回答
  •  北海茫月
    2021-01-19 00:14

    Minimalistic solution comes to my mind is

    import string
    printable_string = filter(lambda x: x in string.printable, your_string)
    ## TODO: substitute your string in the place of "your_string"
    

    If still this doesn't help then try also including uni-code specific [curses.ascii]

提交回复
热议问题