Category:Python: Difference between revisions

From Traxel Wiki
Jump to navigation Jump to search
(Replaced content with "Category:Hacking")
Tag: Replaced
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Hacking]]
[[Category:Hacking]]
= buffering =
Fix CLI buffering in Python with:
<pre>
$ python -u foo.py | tee mylog.log
</pre>
"-u" means unbuffered, or something
= Virtual Environments =
<syntaxhighlight lang="bash">
# Check Python version
python3 --version
# Check pip version
pip3 --version
# Install virtualenv
pip3 install virtualenv
# Navigate to your project directory
cd ~/my_project/
# Create virtual environment
python3 -m venv myenv
# Activate virtual environment
source myenv/bin/activate
# Now you can install packages
pip install <your-package>
# Deactivate when you're done
deactivate
</syntaxhighlight>
= What Libs Have I? =
<pre>
$ pip freeze --local
blinker==1.6.2
click==8.1.7
flask==2.3.3
importlib-metadata==6.8.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
werkzeug==2.3.7
zipp==3.16.2
</pre>
= Package Info =
* https://pypi.org/project/package-name/
** eg: https://pypi.org/project/itsdangerous/
= Datetime and Timestamp =
<pre>
When including time, use one of the following:
pytz.utc.localize(datetime.utcfromtimestamp(ts)) = 1970-01-01 00:00:00+00:00
datetime.fromtimestamp(ts, timezone.utc) = 1970-01-01 00:00:00+00:00
int(dt_with_tz.timestamp()) = 0
now_dt = pytz.utc.localize(datetime.utcnow()) = 2023-09-24 00:01:12.141804+00:00
now_ts = int(now_dt.timestamp()) = 1695513672
now_dt = datetime.fromtimestamp(now_ts, timezone.utc) = 2023-09-24 00:01:12+00:00
now_ts = int(pytz.utc.localize(datetime.utcnow()).timestamp()) = 1695513672
</pre>

Latest revision as of 16:28, 10 November 2023

Pages in category "Python"

The following 7 pages are in this category, out of 7 total.