Python

6680 readers
1 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
276
277
8
submitted 1 year ago* (last edited 1 year ago) by fzz to c/python
 
 

I've just create a little script to install pip in the latest Pythonista with comfort configuration, as I suppose.

This could probably be useful to someone other than me.

screenshotsIMG_0572 1 2 3


❀️‍πŸ”₯

278
 
 

I want to build a python package using setuptools. The folder structure of the project is the following (some non-essential parts have been deleted):

energy-monitor
β”œβ”€β”€ config
β”‚ β”œβ”€β”€ config.yml
β”‚ └── secrets.yml
β”œβ”€β”€ data
β”‚ └── cpu_tdp.json
β”œβ”€β”€ energy_monitor
β”‚ β”œβ”€β”€ core
β”‚ β”‚ β”œβ”€β”€ gui.py
β”‚ β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ data
β”‚ β”‚ └── tableExport.json
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ main.py
β”‚ └── utils
β”‚     β”œβ”€β”€ api_calls.py
β”‚     └── __init__.py
β”œβ”€β”€ energy-monitor.py
β”œβ”€β”€ LICENSE
β”œβ”€β”€ MANIFEST.in
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ README.md
└── requirements.txt

The content of the pyproject.toml file is the following (some non-essential parts have been deleted):

[build-system]
requires = ["setuptools>=68.0"]
build-backend = "setuptools.build_meta"

[project]
name = "energy_monitor"
version = "0.0.1"
description = "Energy monitor"
readme = "README.md"
requires-python = ">=3.11"
license = {text = "GPLv3"}
classifiers = [
  "Programming Language :: Python :: 3",
  "Operating System :: OS Independent",
]
dynamic = ["dependencies"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

[tool.setuptools]
packages = [
  "energy_monitor", 
  "energy_monitor.core", 
  "energy_monitor.utils"
]
include-package-data = true

[project.scripts]
energy-monitor = "energy_monitor.main:main"

Finally, the content of the MANIFEST.in file is the following:

include README.md
include LICENSE
graft config

I generate the package with python -m build and install the .tar.gz archive with pipx. According to setuptools documentation, I expect to find my config folder, together with README and LICENSE in the interpreter directory (site-packages) after the installation. However, this doesn't happen and I cannot run the app becase it complains that it doesn't find the config. What am I missing?

279
280
281
 
 

I can't give you the code because this is work related, and I couldn't make a minimal code that mimics the behavior.

My of my programs at work is a log parser, it reads syslog and use compiled regex pattern to match syslog, the whole program looks like this

If match := pattern.match(line):
  Do this
elif match := pattern2.match(line):
  Do that
…

During almost two years of me developing the programs, there are more patterns and more things to do and it gets slower.

But I recently figure out that if I commented out Do that and replace it with pass, my program speeds up, even if pattern2 never matches in my test case.

More strange thing is that in my attempts to use cProfile to profile things, my program runs 2.5x to 3x faster by just doing

from cProfile import Profile
with Profile() as profile:
  main()

I don't even call anything with profile variable and it speeds up my program, why is that?

282
283
 
 
  • Python 3.12 support.
  • Python 3.7 is no longer supported.
  • Shiboken generator is now available on PyPI.
  • Better asyncio compatibility.
  • Better Android compatibility.
  • aarch64 architecture is now supported.
  • Better access to commercial wheels.
  • Better Python integration in Qt Creator.
  • Out to date research plan for dynamic binding.
284
285
 
 

The thing I love about python is it's elegance; and I thing that is partially due to its syntactic sugar. Between list comprehensions, destructuring, enumerators, generators with yield, and a bunch more, what is your favorite

286
2
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/python
 
 

#XMPP + #Google Summer of Code 2023

Edward initiated discussion session on "Communication & Messaging of the #Future" with 9 participants.

We discussed connection of platforms, importance of information, cultivating community, influence of #AI and #healthy communication. Great exchange!

@RocketChat @python @gnuoctave SociΓ©tΓ© des arts technologiques #openmrs

#chat #gsoc2023
#interoperability #federation #jabber #standards

287
 
 

I'm talking about stuff like this: [file.unlink() for file in files] instead of the more verbose but maybe easier to grasp for python noobs:

for file in files:
    file.unlink()

Maybe with a bit more context:

def _cleanup(self) -> None:                                                                                                                                                                                                             
    dirs, files = partition(lambda f: f.is_file(), self._tmp_dir.rglob("*"))                                                                                                                                                            
    [file.unlink() for file in files]                                                                                                                                                                                                   
    [dir.rmdir() for dir in dirs]                                                                                                                                                                                                       
    self._tmp_dir.rmdir()
288
289
290
13
Calling Rust from Python (blog.frankel.ch)
submitted 1 year ago by [email protected] to c/python
291
 
 

How to take a few images and create custom graphics with Pillow - memes, info-graphics, custom banners and the like.

292
 
 

Examples of how to use amateur astrophotography and machine vision USB cameras with Python (or IronPython sometimes).

293
294
295
296
297
298
299
108
Python 3.12.0 (www.python.org)
submitted 1 year ago by [email protected] to c/python
300
view more: β€Ή prev next β€Ί