Difference between revisions of "Python"

From Ever changing code
Jump to navigation Jump to search
Line 18: Line 18:
It provides the local files browser over http protocol and access logs
It provides the local files browser over http protocol and access logs
  sudo python -m SimpleHTTPServer 80
  sudo python -m SimpleHTTPServer 80
= print() =
Print in v3 is a function, it uses arguments with variables like below:
%s - String (or any object with a string representation, like numbers)
%d - Integers
%f - Floating point numbers
%.<number of digits>f - Floating point numbers with a fixed amount of digits to the right of the dot.
%x/%X - Integers in hex representation (lowercase/uppercase)
Eaxmple:
print("%s is %d years old." % (name, age))


=References=
=References=
*[https://en.m.wikibooks.org/wiki/A_Beginner's_Python_Tutorial A Beginner's Python Tutorial] Wikibooks
*[https://en.m.wikibooks.org/wiki/A_Beginner's_Python_Tutorial A Beginner's Python Tutorial] Wikibooks
*[https://www.google.co.uk/amp/s/pythontips.com/2014/02/04/free-python-books/amp/ List of free Python learning resources ]
*[https://www.google.co.uk/amp/s/pythontips.com/2014/02/04/free-python-books/amp/ List of free Python learning resources ]
*[https://realpython.com/blog/python/vim-and-python-a-match-made-in-heaven/ VIM and Python - a Match Made in Heaven] Vim as Python IDE
*[https://realpython.com/blog/python/vim-and-python-a-match-made-in-heaven/ VIM and Python - a Match Made in Heaven] Vim as Python IDE
*[https://github.com/VundleVim/Vundle.vim Vundle] Vim bundle/plugins manager
*[https://github.com/VundleVim/Vundle.vim Vundle] Vim bundle/plugins manager

Revision as of 16:00, 28 April 2018

Learning Python scratch pad

Vim as Python IDE

Ubuntu comes with vim-tiny package that has most of things disabled, so get it uninstalled

sudo apt-get purge vim-tiny
sudo apt-get install vim         #py3 support
sudo apt-get install vim-nox-py2 #py2 support
vim --version | grep python  #verify you should see eg: +python -python3

Optimally you may need to set alternatives

 sudo update-alternatives --set vim /usr/bin/vim.nox-py2

Now, open vim and check :python import sys; print(sys.version) you should see similar output

2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609]

Simple HTTP Server

It provides the local files browser over http protocol and access logs

sudo python -m SimpleHTTPServer 80

print()

Print in v3 is a function, it uses arguments with variables like below:

%s - String (or any object with a string representation, like numbers)
%d - Integers
%f - Floating point numbers
%.<number of digits>f - Floating point numbers with a fixed amount of digits to the right of the dot.
%x/%X - Integers in hex representation (lowercase/uppercase)

Eaxmple:

print("%s is %d years old." % (name, age))

References