Python

7037 readers
70 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
1
2
3
27
PyPi tariff (pypi.org)
submitted 1 week ago by [email protected] to c/python
 
 

cross-posted from: https://lemmy.world/post/28263533

πŸ‘Š TARIFF πŸ”₯

The GREATEST, most TREMENDOUS Python package that makes importing great again!

TARIFF is a fantastic tool that lets you impose import tariffs on Python packages. We're going to bring manufacturing BACK to your codebase by making foreign imports more EXPENSIVE!

4
5
 
 

I can't get my program to use pandoc from inside a venv.

I can use pandoc from the system context.

From inside the venv

which pandoc
/usr/bin/pandoc 

I've installed pandoc inside the venv with pip, and confirmed the files are in the venv.

What am I missing?

6
 
 

Hello, Python Community!

Has someone been able to successfully connect to an IBM Informix DB with a Python app? I have the following environment: DEV: Windows 11 Python 3.13.3 64-bit VS Code

DB: IBM Informix 12.10 hosted in Azure I'm able to connect to it usind DBeaver (JDBC)

I have tried the following libraries to try to establish the connection: ibm_db: Traceback (most recent call last): File "c:\Users\peterg\source\python\dbApp\ibm_db_test.py", line 1, in <module> import ibm_db as db ImportError: DLL load failed while importing ibm_db: The specified module could not be found._

pyodbc: I have an ODBC DSN connection established Traceback (most recent call last): File "c:\Users\peterg\source\python\dbApp\pyodbc_test.py", line 3, in <module> conn = db.connect("Dsn='DSN_NAME'") pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

JayDeBeAPI: I have downloaded the same JAR files as DBeaver uses and copied them to a dir local to the project and added the CLASSPATH variable: set "CLASSPATH=%PROJECT_ROOT%\Java\jbc-4.50.10.1.jar:%PROJECT_ROOT%\Java\bson-3.8.0.jar"

File "c:\Users\peterg\source\python\dbApp\JayDeBeApi_test.py", line 3, in <module> dbConn = db.connect("com.informix.jdbc.IfxDriver", "jdbc:informix-sqli://hostname:port/db_name:INFORMIXSERVER=server_name", ['user', 'pass']) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jaydebeapi\__init__.py", line 412, in connect jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jaydebeapi\__init__.py", line 221, in _jdbc_connect_jpype jpype.JClass(jclassname) ~~~~~~~~~~~~^^^^^^^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jpype\_jclass.py", line 99, in __new__ return _jpype._getClass(jc) ~~~~~~~~~~~~~~~~^^^^ TypeError: Class com.informix.jdbc.IfxDriver is not found

PyInformix: SADeprecationWarning: The dbapi() classmethod on dialect classes has been renamed to import_dbapi(). Implement an import_dbapi() classmethod directly on class <class 'pyinformix.ifx_jdbc.InformixJDBCDialect'> to remove this warning; the old .dbapi() classmethod may be maintained for backwards compatibility. engine = create_engine('informix+ifx_jdbc://hostname:port/db_name;INFORMIXSERVER=server_name;delimident=y;user=user;password=pass') Traceback (most recent call last): File "c:\Users\peterg\source\python\dbApp\PyInformix_test.py", line 5, in <module> conn = engine.connect() File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\base.py", line 3274, in connect return self._connection_cls(self) ~~~~~~~~~~~~~~~~~~~~^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\base.py", line 146, in __init__ self._dbapi_connection = engine.raw_connection() ~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\base.py", line 3298, in raw_connection return self.pool.connect() ~~~~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 449, in connect return _ConnectionFairy._checkout(self) ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 1264, in _checkout fairy = _ConnectionRecord.checkout(pool) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 713, in checkout rec = pool._do_get() File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\impl.py", line 179, in _do_get with util.safe_reraise(): ~~~~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\util\langhelpers.py", line 146, in __exit__ raise exc_value.with_traceback(exc_tb) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\impl.py", line 177, in _do_get return self._create_connection() ~~~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 390, in _create_connection return _ConnectionRecord(self) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 675, in __init__ self.__connect() ~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 901, in __connect with util.safe_reraise(): ~~~~~~~~~~~~~~~~~^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\util\langhelpers.py", line 146, in __exit__ raise exc_value.with_traceback(exc_tb) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\pool\base.py", line 897, in __connect self.dbapi_connection = connection = pool._invoke_creator(self) ~~~~~~~~~~~~~~~~~~~~^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\create.py", line 646, in connect return dialect.connect(*cargs, **cparams) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\sqlalchemy\engine\default.py", line 625, in connect return self.loaded_dbapi.connect(*cargs, **cparams) # type: ignore[no-any-return] # NOQA: E501 ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jaydebeapi\__init__.py", line 412, in connect jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs) File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jaydebeapi\__init__.py", line 221, in _jdbc_connect_jpype jpype.JClass(jclassname) ~~~~~~~~~~~~^^^^^^^^^^^^ File "C:\Users\peterg\AppData\Local\Programs\Python\Python313\Lib\site-packages\jpype\_jclass.py", line 99, in __new__ return _jpype._getClass(jc) ~~~~~~~~~~~~~~~~^^^^ TypeError: Class com.informix.jdbc.IfxDriver is not found

IfxPy:

Uanble to install, seems that it does not support the latest Python 3 version.

Any help would be appreciated. I can attach the sample code of every method I tried if that would help.

7
 
 

It isn't anything particularly amazing but I'm proud of it! Code can be found here: https://github.com/ArmoredThirteen/PysidianSiteMaker

The general use case is that I'm making a setting and I store all my notes in an Obsidian project. It used to be when I shared notes it was a giant pain trying to send people files so I decided to set up a website. I was using a tool called ObsidianHTML but it doesn't get updated very often and I've had to do some questionable downgrades on my build server to keep using it. It's also way more advanced than what I have use for and I get lost in the aging documentation

So now I'm building a replacement command line tool! My build server picks up on changes made to the settings repo, pulls them in and my PSM code, converts the vault to an html website, and deploys from there. Bonus points is that since my tool is so dedicated purpose the build times have been cut so I can deploy faster than ever

I've never made anything like this before and I'm admittedly not great at Python, I've spent most my time in C#. I know there are lots of areas that aren't written the best and I'm sure there's plenty I don't know about too, despite the small size. I'm always up for feedback!

8
9
10
9
Pytorch internals (blog.ezyang.com)
submitted 2 weeks ago by learnbyexample to c/python
11
24
submitted 2 weeks ago by 3rr4tt1c to c/python
 
 

Was going through a Python tutorial, but it seems kinda dated. Wanted to know if people regularly use docstrings in the workforce. Or are they somewhat irrelevant because you can convey most of that info via comments and context? Do jobs make you use them?

12
13
 
 

Hello if anyone knows of a way to get python-markdown to behave in the way I'd like, or of an alternative way to do it, I'd love some help! My use case is I'm converting .md files made with Obsidian into html files. Obsidian has tags that are a pound sign followed by the tag (so like "#TagName"). When the tag is the first item on a line the pound sign is confused for a heading, even though there is no space after it.

Is there a way that I can avoid this so it only reads it as a heading if there is a space between the pound and the next word? I'm even considering some kind of find/replace logic so I can swap it out with like a link to a page that lists all the pages with that tag or something that gets run before the markdown to html conversion.

Edit: The solution I'm going for is a regex find/replace. Currently the string pattern looks like "#[^\s#][^\s" + string.punctuation + "#]*" which can find tags but ignores headers. Since the ultimate goal is to have the tags link to a tag page anyway I can solve it all in one step by doing a replace with a relevant link.

14
 
 

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

Some custom filter kernel to average out values from a chunk of pixels with some kind of "border aware" behaviour?

15
9
submitted 4 weeks ago* (last edited 4 weeks ago) by [email protected] to c/python
 
 

I have a rather large Python script that I use as basically a replacement for autohotkey. It uses pynput for keyboard and mouse control - and at least on Windows, it works exactly how I expect.

I recently started dual-booting with Linux and have been trying to get the script to work here as well. It does work but with mixed results - in particular, I found that pynput has bizarrely wrong output for special characters, in a way that's both consistent and inconsistent.

The simplest possible case I found that reproduces the error is this script:

import time
from pynput import keyboard

# Sleep statement is just to give time to move the mouse cursor to a text input field
time.sleep(2)

my_kb = keyboard.Controller()

text = 'πŸ†' # Eggplant emoji
my_kb.type(text)

time.sleep(1)

text = 'π•₯𝕖𝕀π•₯' # blackboard bold test
my_kb.type(text)

time.sleep(1)

text = '𝐭𝐞𝐬𝐭' # bold test
my_kb.type(text)

When I run that script right now, it produces the output "πŸ†π•₯π•₯𝕀π•₯𝐭𝐭𝐬𝐭". And if I run it again, it'll produce the same output. And if I change the eggplant emoji to something else, like the regular character 'A', it will still produce the same output (specifically "Aπ•₯π•₯𝕀π•₯𝐭𝐭𝐬𝐭"). But... If I log out and log back in, then the output changes to something else that's still wrong, but differently. For example, when I changed the eggplant to a regular 'A', then relogged, the output became "Aπ•₯𝕖𝕖π•₯𝐭𝐞𝐞𝐭". And then that wrong output will keep being the same wrong output until I log out and back in again. If the test strings don't change, then the incorrect outputs don't change on relog - but if they do, then they do.

In the larger script, errors seemed to chain together somehow - like if I produced an eggplant emoji, then tried to write blackboard bold test, I would get "πŸ†π•–π•€πŸ†". This is despite verifying just before running the pynput.keyboard.Controller.type function that what it was about to type was correct. The issue also happens if I type it character-by-character with press and release functions.

I am very new to Linux. I'm on Linux Mint. I'm running this in a python3 venv that just has pynput and two other external libraries installed. ChatGPT thinks the issue might be related to X11. The issue does not occur at all on Windows, using the exact same code. On Linux there seems to be no issues with typing regular text, just special characters.

16
17
11
submitted 1 month ago by maxint to c/python
18
 
 

I made this Python menu-driven CLI script for yt-dlp. It guides you through a series of menus to download content from a YouTube URL.

If anyone is interested, feedback would be greatly appreciated as only I have tested this so far, and I want to make sure it works for other people's systems.

If you encounter any issues or bugs, let me know so I can fix them!

Edit: I should mention: This is not a pipx package. That was never the intention developing this initially. I might make it a package in the future, but for now, it is just a project directory.

19
20
 
 

if coin == 25 | 10 | 5:

If I replace the '|' with 'or' the code runs just fine. I'm not sure why I can't use '|' in the same statement.

Doing the following doesn't work either:

if coin == 25 | coin == 10 | coin == 5:

I know bitwise operators can only be used with integers, but other then that is there another difference from logical operators?

21
22
24
submitted 1 month ago by sus to c/python
 
 
class Node:
    def __init__(self, edges = set()):
        self.edges = edges


def main():
    foo = Node()
    bar = Node()
    quz = Node()

    foo.edges.add(bar)
    bar.edges.add(foo)

    assert(foo is not bar) # assertion succeeds
    assert(foo is not quz) # assertion succeeds
    assert(bar is not quz) # assertion succeeds
    assert(len(quz.edges) == 0) # assertion fails??


main()

spoilerMutable default values are shared across objects. The set in this case.

23
24
16
Profiling slow imports in Python (jackevans.bearblog.dev)
submitted 1 month ago by norambna to c/python
25
 
 

My personal experience writing a multi-platform desktop app (macOS, Windows, Linux) was rather painful. Tkinter was my first try, but deployment on macOS was a nightmare. I ended using PySide, which ticked all the boxes, but my biggest gripe is that you end with a lot of code that is not very "pythonic". Flet looks like a nice alternative.

view more: next β€Ί