Python: Difference between revisions

From DWIKI
Tony (talk | contribs)
Tag: wikieditor
Tony (talk | contribs)
Tag: wikieditor
 
(7 intermediate revisions by the same user not shown)
Line 3: Line 3:


*[http://www.python.org/ Homepage]  
*[http://www.python.org/ Homepage]  
*[https://peps.python.org/pep-0008/ PEP 8 – Style Guide for Python Code=
==Documentation==
*[https://docs.python.org/3/ Python 3 documentation]
==Tutorials==
*[https://www.w3schools.com/python/ w3schools]
*[https://www.w3schools.com/python/ w3schools]
*[https://www.tutorialspoint.com/python https://www.tutorialspoint.com/python]  
*[https://www.tutorialspoint.com/python https://www.tutorialspoint.com/python]  
*[https://wiki.python.org/moin/BeginnersGuide/Programmers Beginners guide]
*[https://wiki.python.org/moin/BeginnersGuide/Programmers Beginners guide]
=HOWTO=
=HOWTO=
==virtual environment==
==virtual environment (venv)==
===Create virtual environment===
===Create virtual environment===
mkdir myproject
*https://realpython.com/python-virtual-environments-a-primer/
cd myproject
  python -m venv myvenv
  python -m venv venv
and to activate that
  source venv/bin/activate
  source myvenv/bin/activate
and then you can
and then you can
  pip install whatever
  pip install whatever
Line 31: Line 37:
===Link python to python3 on Ubuntu===
===Link python to python3 on Ubuntu===
  update-alternatives --install /usr/bin/python python /usr/bin/python3 1
  update-alternatives --install /usr/bin/python python /usr/bin/python3 1
==Time/datetime==
===Seconds to time===
from datetime import timedelta
myt = timedelta(seconds = 1000)
print(myt)
==Print==
===Print with decimals===
first = 2
second = 3.1415
print("First: {} second {:.2f}".format(first,second))


=Data types=
=Data types=
Line 49: Line 67:


=FAQ=
=FAQ=
==Leave virtualenv==
deactivate
==Python shebang==
#!/usr/bin/env python3
==Error messages==
==-bash: python: command not found==
==-bash: python: command not found==
Try
Try
Line 56: Line 81:
  update-alternatives --install /usr/bin/python python $(which python3) 1
  update-alternatives --install /usr/bin/python python $(which python3) 1


==Leave virtualenv==
deactivate


[[Category:Programming]]
[[Category:Programming]]

Latest revision as of 12:34, 12 May 2026

Links

Documentation

Tutorials

HOWTO

virtual environment (venv)

Create virtual environment

python -m venv myvenv

and to activate that

source myvenv/bin/activate

and then you can

pip install whatever

Leave venv

deactivate

Listen on http

Python http server

python3 -m http.server 8080


Leave virtual environment

deactivate


update-alternatives --install /usr/bin/python python /usr/bin/python3 1

Time/datetime

Seconds to time

from datetime import timedelta
myt = timedelta(seconds = 1000)
print(myt)

Print

first = 2
second = 3.1415
print("First: {} second {:.2f}".format(first,second))

Data types

Tuples

Tuples methods

Regex

Strings

Length of string

len(s)

Lists

List operators

Regular expressions

https://docs.python.org/3/library/re.html

FAQ

Leave virtualenv

deactivate

Python shebang

#!/usr/bin/env python3

Error messages

-bash: python: command not found

Try

update-alternatives --config python

update-alternatives: error: no alternatives for python

update-alternatives --install /usr/bin/python python $(which python3) 1