[Python] Print Formatting

Programming
>>> name = 'Lego Chen'
>>> job = 'engineer'

>>> print '%s is an %s' %(name, job) 
Lego Chen is an engineer

>>> print '%10s is an %20s' %(name, job) 
 Lego Chen is an engineer

>>> print 'The flotting number is: %10.3f' %(1000.33356) 
The flotting number is: 1000.334

>>> print 'First: {x} Second: {x} Third: {y}'.format(x=1, y=2)
First: 1 Second: 1 Third: 2

# python3
>>> print('First: {x} Second: {x} Third: {y}'.format(x=1, y=2))
First: 1 Second: 1 Third: 2

>>> print('{0} {1} {0}'.format(1,2))
1 2 1

>>> print('{:<20} others'.format(1))
1                     others

>>> print('{:>20} others'.format(1))
                    1 others

>>> print('{:b} others'.format(16)) # translate to binary 
10000 others

>>> print('{:o} others'.format(16))# translate to octal 
20 others

>>> print('{:x} others'.format(16)) # translate to Hex
10 others

Here Doc

print("""\
  Hello
  World \n
  bb
""")

Don’t escape

>>> print(r"c:\name\test")
c:\name\test

 

Programming
[Python3] installation – tarball

python packages: https://www.python.org/ftp/python/ I tried install Python-3.6.4  tarball on RHEL6 and RHEL7, looks no problem. Install pre-required packages $ sudo yum install openssl openssl-devel -y Install python3 by tarball $ wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz $ tar -xJf Python-3.6.4.tar.xz $ cd Python-3.6.4 ############## # enable ssl module ############## $ vi Modules/Setup  <= un-comment the following lines # …

jupyter
[Python] Jupyter Server Setup

Purpose: I’d like to setup a jupyter sever that only can be edited by me and I also can share the jupyter notebooks to anyone. There are two URLs, one for admin (me) and another for share to anyone. Admin: https://jupyter-admin.chenlego.me Share(guest): https://jupyter.chenlego.me But, current jupyter server doesn’t support permission management for …

Programming
[Python][Basic] Basic Types

Types Numbers http://nbviewer.jupyter.org/github/jmportilla/Complete-Python-Bootcamp/blob/master/Numbers.ipynb cast int(1.5) => 1 float(1) => 1.0 Difference Python2 vs Python3 In Python 2, the / symbol performs what is known as “classic” division, this means that the decimal points are truncated (cut off). 3/2 => 1 In Python 3 however, a single / performs “true” division. …