Skip to content

Instantly share code, notes, and snippets.

@klimach
Last active September 24, 2018 16:01
Show Gist options
  • Save klimach/24ae75cd4eb3b41ddba4a8226ae263fd to your computer and use it in GitHub Desktop.
Save klimach/24ae75cd4eb3b41ddba4a8226ae263fd to your computer and use it in GitHub Desktop.
week0/lesson2
# Taks 1
# alexandr@Alexandr:~$ pip -V
# pip 18.0 from /home/alexandr/.local/lib/python2.7/site-packages/pip (python 2.7)
# alexandr@Alexandr:~$ pip3 -V
# pip 18.0 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)
# alexandr@Alexandr:~$ virtualenv --version
# 16.0.0
# alexandr@Alexandr:~$ virtualenvwrapper --version
#
# virtualenvwrapper is a set of extensions to Ian Bicking's virtualenv
# tool. The extensions include wrappers for creating and deleting
# virtual environments and otherwise managing your development workflow,
# making it easier to work on more than one project at a time without
# introducing conflicts in their dependencies.
# Taks 2
# alexandr@Alexandr:~$ cd Projects
# alexandr@Alexandr:~/Projects$ virtualenv Py2Env
# New python executable in /home/alexandr/Projects/Py2Env/bin/python
# Installing setuptools , pip, wheel...done.
# alexandr@Alexandr:~/Projects$ virtualenv Py3Env -p python3
# Running virtualenv with interpreter /usr/local/bin/python3
# Using base prefix '/usr'
# /home/alexandr/.local/lib/python2.7/site-packages/virtualenv.py:1041: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
# import imp
# New python executable in /home/alexandr/Projects/Py3Env/bin/python3
# Also creating executable in /home/alexandr/Projects/Py3Env/bin/python
# Installing setuptools, pip, wheel...done.
# alexandr@Alexandr:~/Projects$ source Py2Env/bin/activate
# (Py2Env) alexandr@Alexandr:~/Projects$ python
# Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
# [GCC 7.3.0] on linux2
# Type "help", "copyright", "credits" or "license" for more information.
# >>> print "Hello Cursor"
# Hello Cursor
# >>> quit()
# (Py2Env) alexandr@Alexandr:~/Projects$ deactivate
# alexandr@Alexandr:~/Projects$ source Py3Env/bin/activate
# (Py3Env) alexandr@Alexandr:~/Projects$ python
# Python 3.7.0+ (default, Aug 30 2018, 09:42:00)
# [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
# Type "help", "copyright", "credits" or "license" for more information.
# >>> print "Hello World"
# File "<stdin>", line 1
# print "Hello World"
# ^
# SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello World")?
# >>> print("Hello World")
# Hello World
# >>> quit()
# (Py3Env) alexandr@Alexandr:~/Projects$ deactivate
# Task 3
# alexandr@Alexandr:~/Projects$ mkvirtualenv Py2MkEnv
# New python executable in /home/alexandr/.virtualenvs/Py2MkEnv/bin/python
# Installing setuptools, pip, wheel...done.
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/Py2MkEnv/bin/predeactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/Py2MkEnv/bin/postdeactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/Py2MkEnv/bin/preactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/Py2MkEnv/bin/postactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/Py2MkEnv/bin/get_env_details
# (Py2MkEnv) alexandr@Alexandr:~/Projects$ python
# Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
# [GCC 7.3.0] on linux2
# Type "help", "copyright", "credits" or "license" for more information.
# >>> print "Hello World"
# Hello World
# >>> quit()
# (Py2MkEnv) alexandr@Alexandr:~/Projects$ deactivate
# alexandr@Alexandr:~/Projects$ mkvirtualenv Py3MkEnv -p python3
# Running virtualenv with interpreter /usr/local/bin/python3
# Using base prefix '/usr'
# /home/alexandr/.local/lib/python2.7/site-packages/virtualenv.py:1041: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
# import imp
# New python executable in /home/alexandr/.virtualenvs/Py3MkEnv/bin/python3
# Also creating executable in /home/alexandr/.virtualenvs/Py3MkEnv/bin/python
# Installing setuptools, pip, wheel...done.
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/Py3MkEnv/bin/predeactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/Py3MkEnv/bin/postdeactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/Py3MkEnv/bin/preactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/Py3MkEnv/bin/postactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/Py3MkEnv/bin/get_env_details
# (Py3MkEnv) alexandr@Alexandr:~/Projects$ python
# Python 3.7.0+ (default, Aug 30 2018, 09:42:00)
# [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
# Type "help", "copyright", "credits" or "license" for more information.
# >>> print "Hello World"
# File "<stdin>", line 1
# print "Hello World"
# ^
# SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello World")?
# >>> print("Hello World")
# Hello World
# >>> quit()
# (Py3MkEnv) alexandr@Alexandr:~/Projects$ workon Py2MkEnv
# (Py2MkEnv) alexandr@Alexandr:~/Projects$ python
# Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
# [GCC 7.3.0] on linux2
# Type "help", "copyright", "credits" or "license" for more information.
# >>> quit()
# (Py2MkEnv) alexandr@Alexandr:~/Projects$ deactivate
# Task 4
# alexandr@Alexandr:~$ cd PyCharm/bin
# alexandr@Alexandr:~/PyCharm/bin$ ./pycharm.sh
# alexandr@Alexandr:~/PyCharm/bin$ cd
# alexandr@Alexandr:~$ subl
# alexandr@Alexandr:~$
# Task 5
def create_list(mx:int):
my_list = []
for num in range(1, mx):
if num % 3 == 0 and num % 5 == 0:
my_list.append('FizzBuzz')
elif num % 5 == 0:
my_list.append('Buzz')
elif num % 3 == 0:
my_list.append('Fizz')
else:
my_list.append(num)
return(my_list)
print(create_list(31))
# Result: [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz', 16, 17, 'Fizz', 19, 'Buzz', 'Fizz', 22, 23, 'Fizz', 'Buzz', 26, 'Fizz', 28, 29, 'FizzBuzz']
# alexandr@Alexandr:~$ workon Py3MkEnv
# (Py3MkEnv) alexandr@Alexandr:~$ cd 'Рабочий стол'
# (Py3MkEnv) alexandr@Alexandr:~/Рабочий стол$ subl
# (Py3MkEnv) alexandr@Alexandr:~/Рабочий стол$ python Task5.py
# [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz', 16, 17, 'Fizz', 19, 'Buzz', 'Fizz', 22, 23, 'Fizz', 'Buzz', 26, 'Fizz', 28, 29, 'FizzBuzz']
# (Py3MkEnv) alexandr@Alexandr:~/Рабочий стол$ deactivate
# alexandr@Alexandr:~/Рабочий стол$
# Advanced Level
# alexandr@klimach:~$ subl ~/.virtualenvs/postmkvirtualenv
# #!/bin/bash
# # This hook is sourced after a new virtualenv is activated
# pip install django
# pip install flask
# pip install sphinx
# alexandr@klimach:~$ mkvirtualenv test_0
# Running virtualenv with interpreter /usr/bin/python2
# New python executable in /home/alexandr/.virtualenvs/test_0/bin/python2
# Also creating executable in /home/alexandr/.virtualenvs/test_0/bin/python
# Installing setuptools, pkg_resources, pip, wheel...done.
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/test_0/bin/predeactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/test_0/bin/postdeactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/test_0/bin/preactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/test_0/bin/postactivate
# virtualenvwrapper.user_scripts creating /home/alexandr/.virtualenvs/test_0/bin/get_env_details
# Collecting django
# Using cached https://files.pythonhosted.org/packages/f8/1c/31112c778b7a56ce18e3fff5e8915719fbe1cd3476c1eef557dddacfac8b/Django-1.11.15-py2.py3-none-any.whl
# Collecting pytz (from django)
# Using cached https://files.pythonhosted.org/packages/30/4e/27c34b62430286c6d59177a0842ed90dc789ce5d1ed740887653b898779a/pytz-2018.5-py2.py3-none-any.whl
# Installing collected packages: pytz, django
# Successfully installed django-1.11.15 pytz-2018.5
# Collecting flask
# Using cached https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl
# Collecting Werkzeug>=0.14 (from flask)
# Using cached https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl
# Collecting click>=5.1 (from flask)
# Using cached https://files.pythonhosted.org/packages/34/c1/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77/click-6.7-py2.py3-none-any.whl
# Collecting Jinja2>=2.10 (from flask)
# Using cached https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl
# Collecting itsdangerous>=0.24 (from flask)
# Collecting MarkupSafe>=0.23 (from Jinja2>=2.10->flask)
# Installing collected packages: Werkzeug, click, MarkupSafe, Jinja2, itsdangerous, flask
# Successfully installed Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 click-6.7 flask-1.0.2 itsdangerous-0.24
# Collecting sphinx
# Using cached https://files.pythonhosted.org/packages/35/e0/e9e83b244eaa382ba21896dda6172617e47aff0be225eb72782cca105d3c/Sphinx-1.8.1-py2.py3-none-any.whl
# Collecting sphinxcontrib-websupport (from sphinx)
# Using cached https://files.pythonhosted.org/packages/52/69/3c2fbdc3702358c5b34ee25e387b24838597ef099761fc9a42c166796e8f/sphinxcontrib_websupport-1.1.0-py2.py3-none-any.whl
# Collecting babel!=2.0,>=1.3 (from sphinx)
# Using cached https://files.pythonhosted.org/packages/b8/ad/c6f60602d3ee3d92fbed87675b6fb6a6f9a38c223343ababdb44ba201f10/Babel-2.6.0-py2.py3-none-any.whl
# Collecting imagesize (from sphinx)
# Using cached https://files.pythonhosted.org/packages/fc/b6/aef66b4c52a6ad6ac18cf6ebc5731ed06d8c9ae4d3b2d9951f261150be67/imagesize-1.1.0-py2.py3-none-any.whl
# Requirement already satisfied: setuptools in ./.virtualenvs/test_0/lib/python2.7/site-packages (from sphinx) (40.4.3)
# Collecting packaging (from sphinx)
# Using cached https://files.pythonhosted.org/packages/ad/c2/b500ea05d5f9f361a562f089fc91f77ed3b4783e13a08a3daf82069b1224/packaging-17.1-py2.py3-none-any.whl
# Collecting Pygments>=2.0 (from sphinx)
# Using cached https://files.pythonhosted.org/packages/02/ee/b6e02dc6529e82b75bb06823ff7d005b141037cb1416b10c6f00fc419dca/Pygments-2.2.0-py2.py3-none-any.whl
# Collecting requests>=2.0.0 (from sphinx)
# Using cached https://files.pythonhosted.org/packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl
# Collecting six>=1.5 (from sphinx)
# Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
# Collecting docutils>=0.11 (from sphinx)
# Using cached https://files.pythonhosted.org/packages/50/09/c53398e0005b11f7ffb27b7aa720c617aba53be4fb4f4f3f06b9b5c60f28/docutils-0.14-py2-none-any.whl
# Collecting typing; python_version < "3.5" (from sphinx)
# Using cached https://files.pythonhosted.org/packages/cc/3e/29f92b7aeda5b078c86d14f550bf85cff809042e3429ace7af6193c3bc9f/typing-3.6.6-py2-none-any.whl
# Collecting alabaster<0.8,>=0.7 (from sphinx)
# Using cached https://files.pythonhosted.org/packages/6e/71/c3648cc2f675063dbe2d669004a59e4a5120172713a1de3c3b14144d4b31/alabaster-0.7.11-py2.py3-none-any.whl
# Requirement already satisfied: Jinja2>=2.3 in ./.virtualenvs/test_0/lib/python2.7/site-packages (from sphinx) (2.10)
# Collecting snowballstemmer>=1.1 (from sphinx)
# Using cached https://files.pythonhosted.org/packages/d4/6c/8a935e2c7b54a37714656d753e4187ee0631988184ed50c0cf6476858566/snowballstemmer-1.2.1-py2.py3-none-any.whl
# Requirement already satisfied: pytz>=0a in ./.virtualenvs/test_0/lib/python2.7/site-packages (from babel!=2.0,>=1.3->sphinx) (2018.5)
# Collecting pyparsing>=2.0.2 (from packaging->sphinx)
# Using cached https://files.pythonhosted.org/packages/42/47/e6d51aef3d0393f7d343592d63a73beee2a8d3d69c22b053e252c6cfacd5/pyparsing-2.2.1-py2.py3-none-any.whl
# Collecting idna<2.8,>=2.5 (from requests>=2.0.0->sphinx)
# Using cached https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl
# Collecting certifi>=2017.4.17 (from requests>=2.0.0->sphinx)
# Using cached https://files.pythonhosted.org/packages/df/f7/04fee6ac349e915b82171f8e23cee63644d83663b34c539f7a09aed18f9e/certifi-2018.8.24-py2.py3-none-any.whl
# Collecting chardet<3.1.0,>=3.0.2 (from requests>=2.0.0->sphinx)
# Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
# Collecting urllib3<1.24,>=1.21.1 (from requests>=2.0.0->sphinx)
# Using cached https://files.pythonhosted.org/packages/bd/c9/6fdd990019071a4a32a5e7cb78a1d92c53851ef4f56f62a3486e6a7d8ffb/urllib3-1.23-py2.py3-none-any.whl
# Requirement already satisfied: MarkupSafe>=0.23 in ./.virtualenvs/test_0/lib/python2.7/site-packages (from Jinja2>=2.3->sphinx) (1.0)
# Installing collected packages: sphinxcontrib-websupport, babel, imagesize, pyparsing, six, packaging, Pygments, idna, certifi, chardet, urllib3, requests, docutils, typing, alabaster, snowballstemmer, sphinx
# Successfully installed Pygments-2.2.0 alabaster-0.7.11 babel-2.6.0 certifi-2018.8.24 chardet-3.0.4 docutils-0.14 idna-2.7 imagesize-1.1.0 packaging-17.1 pyparsing-2.2.1 requests-2.19.1 six-1.11.0 snowballstemmer-1.2.1 sphinx-1.8.1 sphinxcontrib-websupport-1.1.0 typing-3.6.6 urllib3-1.23
# (test_0) alexandr@klimach:~$ pip freeze
# alabaster==0.7.11
# Babel==2.6.0
# certifi==2018.8.24
# chardet==3.0.4
# click==6.7
# Django==1.11.15
# docutils==0.14
# Flask==1.0.2
# idna==2.7
# imagesize==1.1.0
# itsdangerous==0.24
# Jinja2==2.10
# MarkupSafe==1.0
# packaging==17.1
# pkg-resources==0.0.0
# Pygments==2.2.0
# pyparsing==2.2.1
# pytz==2018.5
# requests==2.19.1
# six==1.11.0
# snowballstemmer==1.2.1
# Sphinx==1.8.1
# sphinxcontrib-websupport==1.1.0
# typing==3.6.6
# urllib3==1.23
# Werkzeug==0.14.1
# (test_0) alexandr@klimach:~$ deactivate
# alexandr@klimach:~$
# /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment