python intermediate - alessio vaccaro
TRANSCRIPT
set
list tuple set
set()
Sets
methods.intersection().union().difference()
set sets
methods .add() .update() .remove() .discard()
list comprehension lists
generators generator list next()
list list
list list
1
-
1
-
class
class attributes Classmethods class
1. Created a class in a saved script;2. Launched the script in the shell;
class
class attributes Classmethods class
I can access attributes of my class by using the proper syntax.
attributes
function class
class self.year None
__str__ special function
__str__ special function
special function __dict__
special functions
object.__str__(self)
object.__dict__(self)
object.__del__(self)
object.__hash__(self)
object.__repr__(self)
object.__bytes__(self)
object.__format__(self)
special functions
exceptions
handle exception try-except
handle exceptions
Lambdas functions anonymous functions Lambdasfunction
lambda
function
Lambdas attributes functions
Map function list
lists list
lists list list
sum len
lists list list
sum len
list comprehension
for map
sum len
for list comprehension map
• for while
•
•
•
•
•
•
•
•
•
As little as possible
Filter function
filter function numbers_list
lambda function module operator x%2
filter list strings
Python
Python AnacondaPython
libraries
piptcl/tk
other
libraries
piptcl/tk
other
> pip --version> pip 18.1
> pip install matplotlib> # to install something
> py -2 –m pip install matplotlib> # …selecting the right version of Py
> pip install --upgrade matplotlib> # to install and upgrade something
libraries
piptcl/tk
other
piptcl/tk
piptcl/tk
Python
Python
$ virtualenv –p /usr/bin/python3.6 «my_project»
$ source ‘path/to/env/bin/activate’
(my_project) user@localhost:~$
… do things in the environment…
(my_project) user@localhost:~$ deactivate
$
> virtualenv –p /usr/bin/python3.6 «my_project»
> ‘path/to/env/Script/activate’
(my_project) C://path/to/env >
… do things in the environment…
(my_project) C://path/to/env > deactivate
>
py -3 -m venv «my_project»
…
…
Repository
Working copy
Git
$ git config --global user.name "[my username]"
$ git config --global user.email "[my email address]"
$ git init# I initialized my folder as a local repository
$ git clone git://github.com/link_to_project.git# I copy inside my local repository a perfect copy of the remote repository
… hours of work on the code …
$ git add .# my code is now in the staging area ready to be confirmed and committed into my local repository
$ git commit -m ‘Added support to X functionality‘# I committed my code to the local repository
$ git push origin master# I uploaded the content of my local repository to the remote repository
git init
git clone [url]
git add [file]
git add .
git commit –m "[message]"
git push [alias] [branch]
git pull