Sidebar

Python

python
Python norambna β€’ 2 weeks ago β€’ 95%
Python 3.13.0RC2, 3.12.6, 3.11.10, 3.10.15, 3.9.20, and 3.8.20 are now available! discuss.python.org

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

38
6
python
Python jnovinger β€’ 1 year ago β€’ 100%
Welcome to c/Python!

Welcome to c/Python, the go to place to discuss Python tools, techniques, and news. We're just getting started, so please use this thread to suggest what this community should look like, what it should cover, and how it should operate.

51
14
python
Python norambna β€’ 11 hours ago β€’ 91%
Python: my new uv setup for development adamj.eu

via https://fosstodon.org/@adamchainz/113158552844057284

10
0
python
Python norambna β€’ 2 days ago β€’ 97%
Python's many command-line utilities www.pythonmorsels.com

via https://mastodon.social/@treyhunner/113150024938712511

40
0
python
Python norambna β€’ 1 week ago β€’ 97%
uv under discussion on Mastodon https://simonwillison.net/2024/Sep/8/uv-under-discussion-on-mastodon/

via https://fedi.simonwillison.net/@simon/113102865356065670

32
15
python
Python TheButtonJustSpins β€’ 2 weeks ago β€’ 100%
CircuitPython - Trying to set pin value

New to CircuitPython, this feels like it should work according to the docs but it prints six `False`s. Any ideas? ``` #!/usr/bin/env python import board import digitalio import time class body_controller: def __init__(self): SWDIO = board.D5 self._reset_pin = digitalio.DigitalInOut(SWDIO) print(self._reset_pin.value) self._reset_pin.switch_to_output(True) print(self._reset_pin.value) def turn_on(self): print(self._reset_pin.value) self._reset_pin.value = False print(self._reset_pin.value) time.sleep(1) print(self._reset_pin.value) self._reset_pin.value = True print(self._reset_pin.value) body = body_controller() time.sleep(1) body.turn_on() time.sleep(1) ```

11
1
python
Python EvolvedTurtle β€’ 2 weeks ago β€’ 100%
Freelance python

Ive learned a decent bit of python from a trade school I was in and I am really interested in learning more and eventually do freelance work And I'm looking for advice on ensuring I know enough to do that as well as some advice getting started

17
5
python
Python pnutzh4x0r β€’ 2 weeks ago β€’ 100%
Lesser known parts of Python standard library https://www.trickster.dev/post/lesser-known-parts-of-python-standard-library/

> In this article we will explore some lesser known, but interesting and useful corners of Python standard library. ... > To provide more powerful containers for storing data in memory Python ships a `collection` module ... > Python has `with` keyword to create context manager that will auto-cleanup things within lexical scope ... > To address this problem, Python ships `decimal` module that allows us represent decimal numbers as Python objects with operator overloading ... > Likewise, we can run into problem when dealing with fractions - one third is not exactly equal to 0.333… Python ships with `fractions` module to represent them as Python objects with operator overloading ... > The standard Python installation ships with `dis` module that takes Python code units (e.g. a function) and disassembles the code into a kind of pseudo-assembler ... > Python `statistics` module provides a small toolkit of statistical algorithms for relatively simple applications where it is an overkill to use Pandas or Numpy: standard deviation, several kinds of average of numeric data, linear regression, correlation, normal distribution and others ... > To make this easier Python ships a `webbrowser` module with simple API to make a browser show a page ... > To make this less terrible Python ships `zipapp` module with CLI tool and Python API to package Python code into single file packages ...

28
0
python
Python webbureaucrat β€’ 2 weeks ago β€’ 100%
Any advice on picking a Python language server for emacs?

Hi, folks! I'd like to set up my emacs with `lsp-mode` and `lsp-ui`, but I am finding myself in some analysis paralysis. Ruling out the Palantir language server because it's deprecated and because it's Palantir, that still leaves me with *five* [language server recommendations from `lsp-mode`](https://emacs-lsp.github.io/lsp-mode/page/languages/). Anybody have any opinions they'd like to share? Any really bad experiences I should avoid? How do I configure your favorite? (Feel free to assume I know very little about configuring emacs.) If it makes a difference, I am a [poetry](https://python-poetry.org/) user and a religious `mypy --strict` user. Thanks in advance!

15
10
python
Python EveryMuffinIsNowEncrypted β€’ 2 weeks ago β€’ 100%
Confused about multiplying floating-point & integer values https://youtu.be/wgkC8SxraAQ?si=8Mf45sBKo4BR-qX5&t=315

I'm currently doing Dr. Charles Severence's lessons on FreeCodeCamp to try to learn Python3. I'm on lesson exercise 02_03 and confused about multiplying floating-point and integer values. The goal is to write a Python program multiplying hours worked by pay rate to come up with a pay quantity. This is the code I wrote: h = input("Enter hours: ") r = input("Enter pay rate: ") p = float(h) * r I got a traceback error, and the video said the correct way to solve said error was change Line 3 from `p = float(h) * r` to `p = float(h) * float(r)`. However, what I'm confused about is why would I need to change `r` to a floating-point value when it's *already* a floating-point value (since it'd be a currency value like 5.00 or something once I typed it in per the `input()` command*? What am I missing here?   --- *I can't remember: are the individual commands in a python line called "commands"?     --- **Edit**: Wrote plus signs in my post here instead of asterisks. Fixed.   --- **EDIT**: Thanks to [@Labna@lemmy.world](https://lemmy.world/u/Labna) and [@woop_woop@lemmy.world](https://lemmy.world/u/woop_woop). I thought that the `input()` function was a string until the end-user types something in upon being prompted, and then becomes a floating-point value or integer value (or stays a string) according to what was typed. This is incorrect: the value is a string regardless of what is typed unless it is then converted to another type.

6
14
python
Python alexdeathway β€’ 2 weeks ago β€’ 88%
ELI5 Using python virtual environment in docker container.

I read some articles about using a virtual environment in Docker. Their argument are that the purpose of virtualization in Docker is to introduce isolation and limit conflicts with system packages etc. However, aren't Docker and Python-based images (e.g., python:*) already doing the same thing? Can someone eli5 this whole thing?

21
18
python
Python norambna β€’ 2 weeks ago β€’ 91%
Why I Still Use Python Virtual Environments in Docker hynek.me

via https://mastodon.social/@hynek/113067230489781151

40
10
python
Python pnutzh4x0r β€’ 3 weeks ago β€’ 100%
The Design & Implementation of the CPython Virtual Machine blog.codingconfessions.com

> For every bytecode compiled language, the most interesting part of its implementation is its virtual machine (also referred to as the bytecode interpreter) where the bytecode execution takes place. Because this is such a crucial part of the language machinery, its implementation has to be highly performant. Even if you are not a compiler engineer, learning about such internal implementation can give you new performance tricks and insights that you may be able to use in other places of your job. And, if you are a compiler engineer then you should always look around how other languages are implemented to pickup implementation details that you may not be aware of. > In this article, we are going to be discussing the bytecode instruction format of CPython, followed by the implementation of the bytecode evaluation loop of the interpreter where the bytecode execution takes place.

23
1
python
Python BitSound β€’ 3 weeks ago β€’ 88%
A post by Guido van Rossum removed for violating Python community guidelines discuss.python.org

Original comment: > I don’t know much about voting systems, but I know someone who does. Unfortunately he’s currently banned. Maybe we can wait until his 3-month ban expires and ask him for advice? [Previous discussion](https://programming.dev/post/18074128)

67
32
python
Python pnutzh4x0r β€’ 3 weeks ago β€’ 100%
CircuitPython: Python for microcontrollers, simplified https://lwn.net/Articles/983870/

> CircuitPython is an open-source implementation of the Python programming language for microcontroller boards. The project, which is sponsored by Adafruit Industries, is designed with new programmers in mind, but it also has many features that may be of interest to more-experienced developers. The recent 9.1.0 release adds a few minor features, but it follows just a few months after CircuitPython 9.0.0, which brings some more significant changes, including improved graphics and USB support. > CircuitPython is a fork of MicroPython (previously covered on LWN) with several changes designed to make the language easier for beginners to use. CircuitPython has a universal hardware API and is more compatible with the CPython standard library, for example. CircuitPython has some limitations compared to MicroPython, particularly with respect to concurrency, but is otherwise just as powerful. ... > This difference in APIs make sense when looking at the main goals of each project. MicroPython describes the language as ""a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments"". In contrast, Adafruit's "What is CircuitPython?" page says: ""CircuitPython is a programming language designed to simplify experimenting and learning to program on low-cost microcontroller boards."" Adafruit recommends CircuitPython for users who ""want to get up and running quickly"" or ""are new to programming"". > CircuitPython supports most of the core language features of CPython, although some features are missing due to the limited resources found on microcontroller boards compared to the much more powerful computers on which CPython typically runs. Many of those missing features will be the same as those on a comparison between CPython and MicroPython reports. In addition, as CircuitPython's main README explains: ""Modules with a CPython counterpart, such as time, os and random, are strict subsets of their CPython version. Therefore, code from CircuitPython is runnable on CPython but not necessarily the reverse.""

16
1
python
Python jnovinger β€’ 3 weeks ago β€’ 95%
Layman's Guide to Python Built-in Functions Β· Matt Layman www.mattlayman.com

Via https://mastodon.social/@mblayman/113028791455699212

22
1
python
Python uthredii β€’ 4 weeks ago β€’ 98%
uv: Unified Python packaging astral.sh

TL;DR: uv is an extremely fast Python package manager, written in Rust.

89
38
python
Python Bimo β€’ 1 month ago β€’ 95%
Cli Scraper designed to build your own Alibaba Dataset

![](https://lemmy.world/pictrs/image/abd3b43a-c119-427a-a4a0-c27c0e16f96b.png) ![](https://lemmy.world/pictrs/image/ec9b583b-cacf-4ec1-96ad-10b993a63439.jpeg) First thing first, while I started to build this package I've made an error with the word <scraper> that I've misspelled in <scrapper> I'm not a native english speaker. I'm planning to change the name and correct it. So don't be mad with me about it. Ok now let me introduce my first python package. `aba-cli-scrapper`** i'ts a cli tool to easily build a dataset from Alibaba. look at the repo to know more about this project : https://github.com/poneoneo/Alibaba-CLI-Scraper I'm excited to share the latest release of my first Python package, aba-cli-scrapper designed to facilitate data extraction from Alibaba. This command-line tool enables users to build a comprehensive dataset containing valuable information on products and suppliers associated . The extracted data can be stored in either a MySQL or SQLite database, with the option to convert it into CSV files from the SQLite file. The latest feature will be an ai agent to chat with about data saved. I'm working on this. Its should be release very a soon. Key Features: --Asynchronous mode for faster scraping of page results using Bright-Data API key (configuration required) --Synchronous mode available for users without an API key (note: proxy limitations may apply) --Supports data storage in MySQL or SQLite databases --Text mode for thoses who are not comfortable with cli app --Converts data to CSV files from SQLite database Seeking Feedback and Contributions: I'd love to hear your thoughts on this project and encourage you to test it out. Your feedback and suggestions on the package's usefulness and potential evolution are invaluable. Future plans include adding a RAG feature to enhance database interactions. Feel free to try out aba-cli-scrapper and share your experiences! Leave a start if you liked .

20
3
python
Python darshit7 β€’ 1 month ago β€’ 58%
Read about how Python 3.13 will open door for new ear for python community.

Read about how Python 3.13 will open door for new ear for python community. [https://medium.com/@darshit7/beyond-the-gil-future-of-parallel-computing-in-python-38ef2a80555c](https://medium.com/@darshit7/beyond-the-gil-future-of-parallel-computing-in-python-38ef2a80555c) [@python](https://programming.dev/c/python)

5
4
python
Python anzo β€’ 1 month ago β€’ 100%
Efficiently Manage Memory Usage in Pandas with Large Datasets geekpython.in

cross-posted from: https://lemm.ee/post/39533101

15
2
python
Python pnutzh4x0r β€’ 1 month ago β€’ 95%
Core Python developer suspended for three months www.theregister.com

> The Python Steering Council has decided to suspend a core Python developer for three months for alleged Code of Conduct violations. > Citing the recommendation of the Code of Conduct Working Group, Python developer Thomas Wouters revealed on behalf of the Steering Council that the unidentified developer was deemed to have repeatedly violated the Python Software Foundation (PSF) [Code of Conduct](https://policies.python.org/python.org/code-of-conduct/). > The suspended developer is Tim Peters, who told The Register it was fine to name him but declined to comment – beyond observing that one of his objections to the governance process is the secrecy involved.

65
39
python
Python pnutzh4x0r β€’ 1 month ago β€’ 98%
GIL Become Optional in Python 3.13 geekpython.in

> GIL or Global Interpreter Lock can be disabled in Python version 3.13. This is currently experimental. > Python 3.13 brings major new features compared to Python 3.12 and one of them is free-threaded mode, which disables the Global Interpreter Lock, allowing threads to run more concurrently. > The GIL will be disabled when you configure the Python with the `--disable-gil` option which is nothing but a build configuration (free threading build) at the time of installation. > This will allow optionally enabling and disabling GIL using the environment variable `PYTHON_GIL` which can be set to 1 and 0 respectively. > It will also provide a command-line option `-X gil` which can also be set to 0 (disable) and 1 (enable).

61
5
python
Python SpongeB0B β€’ 1 month ago β€’ 92%
Installing gunicorn once on the OS and reuse it between venv ?

Hi, I use [gunicorn](https://gunicorn.org) in my [venv](https://docs.python.org/3/library/venv.html) I have quite few `venv` that run gunicorn. I would like to reuse `gunicorn` for other `venv` I launch my web application like this ```bash #PWD = venv dir source ./bin/activate gunicorn A_WebApp:app #A_WebApp is my python file A_WebApp.py ``` I supposes that `gunicorn` is a shell program ? if yes I should use `$PATH` ? \ or `gunicorn` is a Python program only ? and then what I should do to use gunicorn in another `venv` ? Thanks.

12
11
python
Python batmaniam β€’ 1 month ago β€’ 100%
Simple average color library for video? (edit: closed, problem wasn't the problem)

Hi All, I'm screening a large media library (20TB) wherein some files got corrupted when I did a transfer via filezilla (by my guess ~10%). The corrupted files display with a green "filter" over every frame (when played via plex and a number of local video players playing the file directly). I'd like to screen the library, and want to write a script to get an average color reading. Are there any libraries that would let me return a value AND specify how many frames I want it to take the average of? Because of how consistent and defined the issue is, it's really not necessary to average the whole file. It would also be great if it automatically skipped non-video files, but I imagine a simple "try/except" would be fine. My skill level here is best described as "high level hobbyist". I'm familiar with what I need to do iterating over the folder etc, but would prefer not to learn how to pull specific frames from a video container unless I have to. Thanks for any help!

13
2
python
Python Zara β€’ 2 months ago β€’ 94%
Do you know a CCTV software write in Python ?

cross-posted from: https://lemmy.ml/post/18540661 > Hi, > > I'm looking for a software similar to ZoneMinder \ > https://lemmy.ml/post/18530232 > > But it seem that ZoneMinder become slowly outdated, php etc.. > > I've found a couples of alternatives ( hard choice as the limitations of use are often buried deep ) > > It seem that [openCV](https://pypi.org/project/opencv-python/) is really famous for AI Computer vision, So I would be surprise if there were no Python program to manage cameras like a ZoneMinder !? > > Do you know any ? > > Thanks.

15
3
python
Python Berin β€’ 2 months ago β€’ 100%
New Community for Ren'Py Game Engine

cross-posted from: https://mastodon.social/users/Berin/statuses/112836125469155607 > New Ren'Py Lemmy Community! > > Heyo, I made a community for Ren'Py developers to ask for help and share their projects! Feel free to tag it to crosspost your mastodon posts, just like this post here. (But read the rules first, please) > > [https://discuss.tchncs.de/c/renpy](https://discuss.tchncs.de/c/renpy) > > [@renpy](https://discuss.tchncs.de/c/renpy) > > [\#RenPy](https://mastodon.social/tags/RenPy) [#GameDev](https://mastodon.social/tags/GameDev) [#VNDev](https://mastodon.social/tags/VNDev) [#IndieDev](https://mastodon.social/tags/IndieDev) [#VisualNovel](https://mastodon.social/tags/VisualNovel) Hello Python community! I wanted to present the newly-made Ren'Py community on here. Ren'Py is a Python-based game engine for visual novel development aimed at beginner developers with little prior programming experience. It uses a simple movie script-like syntax and provides both must-have visual novel components and tons of quality-of-life features out of the box. Capable Python programmers can easily extend the framework via custom components. If you ever wanted to create an interactive fiction game, feel free to take a look! !renpy@discuss.tchncs.de

30
1
python
Python learnbyexample β€’ 2 months ago β€’ 100%
Interactive TUI app with 100+ Python re(gex)? exercises github.com

I wrote a TUI application to help you practice Python regular expressions. There are more than 100 exercises covering both the builtin `re` and third-party `regex` module. If you have `pipx`, use `pipx install regexexercises` to install the app. See the repo for source code and other details.

29
3
python
Python rimu β€’ 2 months ago β€’ 94%
An HTMX success story https://www.sheenaoc.com/articles/2024-06-30-htmx

Porting from Django+React to a Django+HTMX based stack

30
1
python
Python s12 β€’ 3 months ago β€’ 100%
How should I deal with multiple imports having the same name? stackoverflow.com

I have a repository that contains multiple programs: . └── Programs Β Β  β”œβ”€β”€ program1 Β Β  β”‚Β Β  └── Generic_named.py Β Β  └── program2 Β Β  └── Generic_named.py I would like to add testing to this repository. I have attempted to do it like this: . β”œβ”€β”€ Programs β”‚Β Β  β”œβ”€β”€ program1 β”‚Β Β  β”‚Β Β  └── Generic_named.py β”‚Β Β  └── program2 β”‚Β Β  └── Generic_named.py └── Tests β”œβ”€β”€ mock β”‚Β Β  β”œβ”€β”€ 1 β”‚Β Β  β”‚Β Β  └── custom_module.py β”‚Β Β  └── 2 β”‚Β Β  └── custom_module.py β”œβ”€β”€ temp β”œβ”€β”€ test1.py └── test2.py Where `temp` is a folder to store each program temporarily with mock versions of any required imports that can not be stored directly with the program. Suppose we use a hello world example like this: cat Programs/program1/Generic_named.py import custom_module def main(): return custom_module.out() cat Programs/program2/Generic_named.py import custom_module def main(): return custom_module.out("Goodbye, World!") cat Tests/mock/1/custom_module.py def out():return "Hello, World!" cat Tests/mock/2/custom_module.py def out(x):return x And I were to use these scripts to test it: cat Tests/test1.py import unittest import os import sys import shutil if os.path.exists('Tests/temp/1'): shutil.rmtree('Tests/temp/1') shutil.copytree('Tests/mock/1', 'Tests/temp/1/') shutil.copyfile('Programs/program1/Generic_named.py', 'Tests/temp/1/Generic_named.py') sys.path.append('Tests/temp/1') import Generic_named sys.path.remove('Tests/temp/1') class Test(unittest.TestCase): def test_case1(self): self.assertEqual(Generic_named.main(), "Hello, World!") if __name__ == '__main__': unittest.main() cat Tests/test2.py import unittest import os import sys import shutil if os.path.exists('Tests/temp/2'): shutil.rmtree('Tests/temp/2') shutil.copytree('Tests/mock/2', 'Tests/temp/2') shutil.copyfile('Programs/program2/Generic_named.py', 'Tests/temp/2/Generic_named.py') sys.path.append('Tests/temp/2') import Generic_named sys.path.remove('Tests/temp/2') class Test(unittest.TestCase): def test_case1(self): self.assertEqual(Generic_named.main(), "Goodbye, World!") if __name__ == '__main__': unittest.main() Both tests pass when run individually: python3 -m unittest Tests/test1.py . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK python3 -m unittest Tests/test2.py . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK However, they fail when being run together: python3 -m unittest discover -p test*.py -s Tests/ .F ====================================================================== FAIL: test_case1 (test2.Test) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/s/Documents/Coding practice/2024/Test Mess/1/Tests/test2.py", line 18, in test_case1 self.assertEqual(Generic_named.main(), "Goodbye, World!") AssertionError: 'Hello, World!' != 'Goodbye, World!' - Hello, World! + Goodbye, World! ---------------------------------------------------------------------- Ran 2 tests in 0.001s FAILED (failures=1) If I try to use a different temporary name for one of the scripts I am trying to test, cat Tests/test2.py import unittest import os import sys import shutil if os.path.exists('Tests/temp/2'): shutil.rmtree('Tests/temp/2') shutil.copytree('Tests/mock/2', 'Tests/temp/2') shutil.copyfile('Programs/program2/Generic_named.py', 'Tests/temp/2/Generic_named1.py') sys.path.append('Tests/temp/2') import Generic_named1 sys.path.remove('Tests/temp/2') class Test(unittest.TestCase): def test_case1(self): self.assertEqual(Generic_named1.main(), "Goodbye, World!") if __name__ == '__main__': unittest.main() Then I get a different error: python3 -m unittest discover -p test*.py -s Tests/ .E ====================================================================== ERROR: test_case1 (test2.Test) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/s/Documents/Coding practice/2024/Test Mess/2/Tests/test2.py", line 18, in test_case1 self.assertEqual(Generic_named1.main(), "Goodbye, World!") File "/home/s/Documents/Coding practice/2024/Test Mess/2/Tests/temp/2/Generic_named1.py", line 4, in main return custom_module.out("Goodbye, World!") TypeError: out() takes 0 positional arguments but 1 was given ---------------------------------------------------------------------- Ran 2 tests in 0.001s FAILED (errors=1) It seems to be trying to import the same file, despite me using a different file from a different path with the same name. This seems strange, as I've been making sure to undo any changes to the Python Path after importing what I wish to test. Is there any way to mock the path? I can't change the name of the `custom_module`, as that would require changing the programs I wish to test. How should I write, approach, or setup these tests such that they can be tested with unittest discover the same as they can individually?

11
4