1
20
Python 3.14.0 alpha 2 (discuss.python.org)
2
104
3
20
4
8
submitted 3 hours ago by daco@lemm.ee to c/python@programming.dev

Hi,

I wanted to use d2 in an environment where I could only install python and npm packages.

Given that, and that I could not find any other solution, I made d2-python-wrapper, a small python wrapper that bundles the d2 binaries.

Now you can use d2 from python like this:

from d2_python import D2

d2 = D2()

# Simple diagram
with open("test.d2", "w") as f:
    f.write("x -> y")

# Default SVG output
d2.render("test.d2", "output.svg")

# PDF output with specific theme
d2.render("test.d2", "output.pdf", format="pdf", theme="1")

The class just wraps the bin, so it works and supports the same as the bin. There is a GitHub Action that gets the bins for each platform (mac, win, linux) from the releases in this repo and publishes it to pip.

You can install this using

pip install d2-python-wrapper

Here is a short post with more context.

Just in case It's useful for anyone. 😁

5
26

Welcome to a new era of interconnected content discussion with PieFed – a link aggregator, a forum, a hub of social interaction and information, built for the fediverse. Our focus is on individual control, safety, and decentralised power.


Like other platforms in the fediverse, we are a self-governed space for social link aggregation and conversation. We operate without the influence of corporate entities – ensuring that your experience is free of advertisements, invasive tracking, or secret algorithms. On our platform, content is grouped into communities, allowing you to engage with topics of interest and disregard the irrelevant ones. We utilise a voting system to highlight the best content.


Video introduction the codebase

6
34
Is Python Really That Slow? (blog.miguelgrinberg.com)
7
18
Python's pathlib module (www.pythonmorsels.com)
8
12
What's new in pip 24.3 (ichard26.github.io)
9
6
Are we PEP 740 yet? 🔏 (trailofbits.github.io)
10
15
All About Decorators in Python (www.pythonmorsels.com)
11
10
12
11
submitted 2 weeks ago* (last edited 1 week ago) by Rick_C137@programming.dev to c/python@programming.dev

Hi,

I've discover haml and pug [^1] ( both web template engine )

It's totally Pytonic ! ( and make even more sense to use it with python rather than JS 🤮 )

I've look, if it exist for Python, but so far, I've found only

The first, only convert pug into another template :/
The second, didn't pass the alpha version.
The third, require dependence, not maintained etc.. \

So I didn't found a Python package that could do haml/pug to html directly, without too much dependence...

For example:

From

html
  head title Example for Python discuss
  body
    h1 Hello world
    p This is a paragraph.

To

<html>
  <head>
    <title>Example for Python discuss</title>
  </head>
  <body>
    <h1>Hello world</h1>
    <p>This is a paragraph.</p>
  </body>
</html>

Do you know if such thing exist ?
If not, I will build my own (FLOSS). ( I'm open to any advice to do so :) )

Thanks

[^1]:Pug is a template engine heavily influenced by Haml and implemented with JavaScript 🤮 for Node.js

13
12
submitted 2 weeks ago* (last edited 2 weeks ago) by Rick_C137@programming.dev to c/python@programming.dev

Hi,

I'm following my previous post
How encrypt email with a GnuPG public key ? [ solved ]

So I managed to encrypt the email body with GnuPG public key.. But I don't figure how I can do the same for the title ?!
ThunderBird manage it.. any idea how ?
asked on Official Thunderbird forum

Thanks.

14
12

From Enaml's docs:

Enaml brings the declarative UI paradigm to Python in a seamlessly integrated fashion. The grammar of the Enaml language is a strict superset of Python. This means that any valid Python file is also a valid Enaml file, though the converse is not necessary true. The tight integration with Python means that the developer feels at home and uses standard Python syntax when expressing how their data models bind to the visual attributes of the UI.

. . .

Enaml’s declarative widgets provide a layer of abstraction on top of the widgets of a toolkit rendering library. Enaml ships with a backend based on Qt5/6 and third-party projects such as enaml-web and enaml-native provides alternative backends.


A maintainer of Enaml has just opened a brainstorm discussion on the next major development goals.

It's a project I've long admired, though rarely used, and I'd love to see it get some attention and a revamp. I think the bar these days has been raised by projects like QML and Slint, which provide a great context in which to set new goals.

15
271
submitted 2 weeks ago by neme@lemm.ee to c/python@programming.dev
16
49
submitted 3 weeks ago* (last edited 2 weeks ago) by EveryMuffinIsNowEncrypted@lemmy.blahaj.zone to c/python@programming.dev

Note: The attached image is a screenshot of page 31 of Dr. Charles Severance's book, Python for Everybody: Exploring Data Using Python 3 (2024-01-01 Revision).


I thought = was a mathematical operator, not a logical operator; why does Python use

>= instead of >==, or <= instead of <==, or != instead of !==?

Thanks in advance for any clarification. I would have posted this in the help forums of FreeCodeCamp, but I wasn't sure if this question was too.......unspecified(?) for that domain.

Cheers!

 


Edit: I think I get it now! Thanks so much to everyone for helping, and @FizzyOrange@programming.dev and @itslilith@lemmy.blahaj.zone in particular! ^_^

17
11
🧵 Free-Threaded Wheels (hugovk.github.io)

via https://mastodon.social/@hugovk/113385974873569374

hugovk.github.io/free-threaded-wheels/ tracks how many of the top 360 PyPI packages have free-threaded wheels.

Green packages (currently 3%) offer has free-threaded wheels

Uncoloured packages (82%) offer pure-Python wheels

Orange packages (16%) have no wheels ready for free-threading (yet!)

See also Quansight Labs' https://py-free-threading.github.io/tracking/ for a smaller yet fine-grained tracker that also includes build tools.

18
39
19
10
20
35
21
7

I store my programs in a cryptomator vault which uses a fuse virtual drive (The default on Linux), but when trying to update pip inside a venv I get an error, then any subsequent use of pip also throws an error and {path_to_venv}/lib/python3.12/site-packages/pip/ becomes empty.

I imagine this is an issue that would happen in any FUSE drive although I don't know how to test that.

Here are the logs

  • OS : Fedora 40
  • pip version: 23.3.2 updating to 24.2
  • python version: 3.12.7

I already made a bug report on the github

Does anyone know a temporary workaround for this ?

22
11
Started a Simulation with Python Blog (quantasticjourney.blogspot.com)

The first post of a new python blog I started if anyone is interested.

23
35

I am including the full text of the post


Despite not being a pure functional language, a lot of praise that python receives are for features that stem from functional paradigms. Many are second nature to python programmers, but over the years I have seen people miss out on some important features. I gathered a few, along with examples, to give a brief demonstration of the convenience they can bring.

Replace if/else with or

With values that might be None, you can use or instead of if/else to provide a default. I had used this for years with Javascript, without knowing it was also possible in Python.

def get_greeting_prefix(user_title: str | None):
	if user_title:
		return user_title
	return ""

Above snippet can shortened to this:

def get_greeting_prefix(user_title: str | None):
	return user_title or ""

Pattern Matching and Unpacking

The overdue arrival of match to python means that so many switch style statements are expressed instead with convoluted if/else blocks. Using match is not even from the functional paradigm, but combining it with unpacking opens up new possibilities for writing more concise code.

Let's start by looking at a primitive example of unpacking. Some libraries have popularised use of [a, b] = some_fun(), but unpacking in python is much powerful than that.

[first, *mid, last] = [1, 2, 3, 4, 5]
# first -> 1, mid -> [2, 3, 4], last -> 5

Matching Lists

Just look at the boost in readability when we are able to name and extract relevant values effortlessly:

def sum(numbers: [int]):
	if len(numbers) == 0:
		return 0
	else:
		return numbers[0] + sum(numbers[1:])
def sum(numbers: [int]):
	match numbers:
		case []:
			return 0
		case [first, *rest]:
			return first + sum(rest)

Matching Dictionaries

Smooth, right? We can go even further with dictionaries. This example is not necessarily better than its if/else counterpart, but I will use it for the purpose of demonstrating the functionality.

sample_country = {"economic_zone": "EEA", "country_code": "AT"}

def determine_tourist_visa_requirement(country: dict[str, str]):
	match country:
		case {"economic_zone": "EEA"}:
			return "no_visa"
		case {"country_code": code} if code in tourist_visa_free_countries:
			return "non_tourist_visa_only"
		case default:
			return "visa_required"		

Matching Dataclasses

Let’s write a function that does a primitive calculation of an estimated number of days for shipment

@dataclass
class Address:
	street: str
	zip_code: str
	country_code: str
def calculate_shipping_estimate(address: Address) -> int:
	match address:
		case Address(zip_code=zc) if close_to_warehouse(zc):
			return 1
		case Address(country_code=cc) if cc in express_shipping_countries:
			return 2
		case default:
			return provider_estimate(city.coordinates)

Comprehensions

List comprehensions get their deserved spotlight, but I’ve seen cases where dictionary comprehension would’ve cut multiple lines. You can look at examples on this page on python.org

24
14
25
47

I am working on a rudimentary Breakout clone, and I was doing the wall collision. I have a function that I initially treated as a Boolean, but I changed it to return a different value depending on which wall the ball hit. I used the walrus operator to capture this value while still treating the function like a bool. I probably could have just defined a variable as the function's return value, then used it in an if statement. But it felt good to use this new thing I'd only heard about, and didn't really understand what it did. I was honestly kind of surprised when it actually worked like I was expecting it to! Pretty cool.

view more: next ›

Python

6394 readers
79 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 1 year ago
MODERATORS