[GO] python> Check if code is printable> Use ord () / all (c in string.printable for c in hello)

I want to check whether the RS-232C communication code is a control character such as <ACK> or a printable one such as G.

Reference http://python.civic-apps.com/char-ord/

I implemented the following.

http://ideone.com/XKsbnY

checkCode.py


def	checkCode(code):
	if ord(code) < 32:
		print "not printable"
		
	if ord(code) >= 32:
		print "printable:", code	


code = chr(6) # <ACK>
checkCode(code)

code = chr(71) # G
checkCode(code)

result


Success	time: 0.01 memory: 8968 signal:0
not printable
printable: G

http://stackoverflow.com/questions/3636928/test-if-a-python-string-is-printable According to it, there is also the following writing style.

>>> import string
>>> all(c in string.printable for c in hello)
True

Recommended Posts

python> Check if code is printable> Use ord () / all (c in string.printable for c in hello)
Check if the string is a number in python
How to use any or all to check if it is in a dictionary (Hash)
Check what the character code is for all files under the directory that is Python and output
Check for memory leaks in Python
Check for external commands in python
Use fabric as is in python (fabric3)
How to use the asterisk (*) in Python. Maybe this is all? ..
Inject is recommended for DDD in Python
Check if the URL exists in Python
Check if the characters are similar in Python
Python> Run-time argument> Check if -d is attached
Boost.NumPy Tutorial for Extending Python in C ++ (Practice)
python> use c quick swap> #if 1 // no reshape
Don't use readlines () in your Python for statement!
Use Python in Anaconda environment with VS Code
(For myself) Flask_AWS_3 (Check if SQL is working)
Settings for Python coding in Visual Studio Code
Wrap C ++ with Cython for use from Python
Implement "All You Need Is Kill" in Python
How to check in Python if one of the elements of a list is in another list
I want to write in Python! (1) Code format check
[For beginners] How to use say command in python!
Specific sample code for working with SQLite3 in Python
VS Code settings for developing in Python with completion
Check if it is Unix in the scripting language
python> check NoneType or not> if a == None:> if a is None:
Check if it is Unix in the scripting language
Expose settings.json for efficient Python coding in VS Code
Python code for k-means method in super simple case