Content
NoteCode | Purpose | Syntax | Additional Information |
?AN001 | Dealing with Japanese character /format [String encoding] | QtCore.QString.fromUtf8 |
|
AN002 | Using Japanese character inside the source file (.py) [File encoding] | # -*- coding: utf-8 -*- | Keyword: file encoding, UTF8 |
AN002 | Print without newline | from __future__ import print_function | Keyword: __future__ , print statement, print() function, Python 3, Python 2.6, end |
AN001
Purpose: Dealing with Japanese character /format [String encoding]
Library: PySide (using QtCore)
Keyword: try, except, AttributeError, def, UTF8 Endoding, string encoding
What is
UTF8 Encoding: Unicode Transformation Format, that uses 8-bit blocks to represent characters
try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromUtf8(s): return s
Code location: at the beginning (header)
AN002
Purpose: Using Japanese character inside the source file (.py) [File encoding]
Keyword: file encoding, UTF8
# -*- coding: utf-8 -*-
Code location: at the VERY beginning (header)
AN003
Purpose: Print without newline
Keyword: __future__ , print statement, print() function, Python 3, Python 2.6, end
- Currently & previously (before Python 3):
print is a statement, and the resulted printed text always end with newline (or whitespace, if print command is ended with comma ‘,’) - After Python 3:
print becomes function (instead of statement) print() and argument “end” can be used to specify the end of printed text - How to use print() if installed python version is still Python 2.6 (and above):
using code
from __future__ import print_function
print("\t", end="")
_