Python

From DWIKI
Revision as of 10:47, 23 January 2026 by Tony (talk | contribs) (Seconds to time)

Links

Tutorials

HOWTO

virtual environment (venv)

Create virtual environment

mkdir myproject
cd myproject
python -m venv venv
source venv/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