Close

python

Python – crash course

To install python: $ yum install python indentation is important, since code blocks are not encased in any brackets whatsoever. to access python command line (aka repl) do: [root@ansibleclient01 ~]# python Python 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 Type “help”, “copyright”, “credits” […]

Read More

Python – Virtualenv

Virtualenv is the ruby equialent of ruby’s rbm. To start using Virtualenv, you need to run the following as the root user: $ yum install python-pip $ pip install virtualenv $ pip install virtualenvwrapper # optional but provides the workon From this point forward you can run all other commands […]

Read More

Python – Pip

https://pip.pypa.io/en/stable/ To install python on centos: $ yum install python-pip Some useful commands: $ pip list # equivalent to: yum list aailable … $ pip show {packagename} # equivalent to: yum info …. $ pip search {keyworld} # equivalent to: yum search …. https://pypi.python.org/pypi # equivalent to rubygems.org In Ruby, […]

Read More

Python – Navigation directories

If you want to do pwd, cd, and ls, then you need to import the os module first: [python] import os [/python] Now we have the following functions: [python] =>=>=> os.getcwd() # equivalent to pwd ‘C:\\users\\mir’ =>=>=> os.chdir("C:/") # equivalent to cd =>=>=> os.listdir() # equivalent to ls [‘$AVG’, ‘$Recycle.Bin’, […]

Read More

Python – run python scripts

You have to do this from the powershell command line:   user powershell to cd to the directory containin the py file. from the powershell command line type “python {script-name}.py”   to load From within python, check out:   http://stackoverflow.com/questions/436198/what-is-an-alternative-to-execfile-in-python-3-0 This link says you need to navigate to the python […]

Read More

Python – Using the builtin software repo, Pip

Pip is the python equivalent of “linux redhat’s yum”   It comes included with python 3.4.   it is something that you run from the powershell command line rather than within python terminal itself, e.g. [powershell] PS C:\Users\Mir\Desktop=> pip install -U selenium Downloading/unpacking selenium Running setup.py (path:C:\Users\Mir\AppData\Local\Temp\pip_build_Mir\selenium\setup.py) egg_info for package […]

Read More

Python – Installing and Getting Started

There are 2 versions of python v2.x.x and version v3.x.x.x v3 is actually a complete rewrite of v2 and will eventually replace v2. v2 is therefore legacy and you should avoid using it if possible.     Most linux distro comes with python as standard. Python works example the same […]

Read More

Python – Hello world

Everytime you run a python command, python does does the following steps in sequence: Read Evaluate Print           – if anything needs printing. Loopback     – go back to the command line The above is called “repl” for short.   To print anything, you need […]

Read More

Python – The For-Loop

Here is a simple for loop which we’ll demonstrate using the range function. In Pyth+on, a block of code is indicated by white space indents rather than encasing it brackets. [python] =>=>=> for i in range(5): … x = i * 10 # note the 4 space indent … print(x) […]

Read More