Python

6287 readers
8 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
126
4
submitted 8 months ago by [email protected] to c/python
 
 

I want to write my python code using thonny, but I seem to be getting some error when trying to open a file in thonny (Ctrl + O) and when instantiating a window, for example with TKinter. The exact error can be found here:

17:21:40.785 WARNING thonny.ui_utils: Zenity returned code 255 and stderr 'Diese Option steht nicht zur Verfügung. Bitte verwenden Sie »--help« für alle Anwendungsmöglichkeiten.\n' The text is german and says "This option is not available. lease use --help for viewing all options". For now I'll just use vim instead, but I really wanna go back to thonny. Has anyone ever experienced something like this before?

In case it matters, here is output I get from the terminal when running the program on startup:


17:25:36.099 INFO    thonny: Thonny version: 4.0.1
17:25:36.099 INFO    thonny: cwd: /home/marty
17:25:36.099 INFO    thonny: original argv: ['/usr/bin/python3', '/usr/bin/thonny']
17:25:36.100 INFO    thonny: sys.executable: /usr/bin/python3
17:25:36.100 INFO    thonny: sys.argv: ['/usr/bin/thonny']
17:25:36.100 INFO    thonny: sys.path: ['/usr/bin', '/usr/lib/python311.zip', '/usr/lib/python3.11', '/usr/lib/python3.11/lib-dynload', '/home/marty/.local/lib/python3.11/site-packages', '/usr/local/lib/python3.11/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.11/dist-packages']
17:25:36.100 INFO    thonny: sys.flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0, dev_mode=False, utf8_mode=0, warn_default_encoding=0, safe_path=False, int_max_str_digits=-1)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/thonny/__init__.py", line 235, in launch
    _delegate_to_existing_instance(sys.argv[1:])
  File "/usr/lib/python3/dist-packages/thonny/__init__.py", line 322, in _delegate_to_existing_instance
    sock, secret = _create_client_socket()
                   ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/thonny/__init__.py", line 365, in _create_client_socket
    client_socket.connect(get_ipc_file_path())
ConnectionRefusedError: [Errno 111] Connection refused
17:25:37.820 INFO    thonny.plugins.cpython_frontend.cp_front: Creating LocalCPythonProxy
17:25:37.820 INFO    thonny.running: Starting the backend: ['/usr/bin/python3', '-u', '-B', '-m', 'thonny.plugins.cpython_backend.cp_launcher', '/home/marty'] /home/marty
127
128
30
submitted 8 months ago by mac to c/python
129
39
RustPython (rustpython.github.io)
submitted 8 months ago by [email protected] to c/python
130
8
submitted 8 months ago* (last edited 8 months ago) by [email protected] to c/python
 
 

I deploy a FastAPI service with docker (see my docker-compose.yml and app).

My service directory gets filled with files index.html, index.html.1, index.html.2,... that all contain

They seem to be generated any time the docker healthcheck pings the service.

How can I get rid of these?

PS: I had to put a screenshot, because Lemmy stripped my HTML in the code quote.

131
 
 

Smassh is a TUI based typing test application inspired by MonkeyType -- A very popular online web-based typing application

Smassh tries to be a full fledged typing test experience but not missing out on looks and feel! There is a lot of room for improvements/additions and I am open to contributions and suggestions!

Github: https://github.com/kraanzu/smassh

Thank you! <3

132
 
 

I want to scrape a website using python selenium however every time it gives different id to same html element. I don't know how to circumvent it.

maybe XPATH is my saviour? but I don't know how reliable it is.

133
134
 
 

I often find myself defining function args with list[SomeClass] type and think "do I really care that it's a list? No, tuple or Generator is fine, too". I then tend to use Iterable[SomeClass] or Collection[SomeClass]. But when it comes to str, I really don't like that solution, because if you have this function:

def foo(bar: Collection[str]) -> None:
    pass

Then calling foo("hello") is fine, too, because "hello" is a collection of strings with length 1, which would not be fine if I just used list[str] in the first place. What would you do in a situation like this?

135
8
submitted 8 months ago by [email protected] to c/python
 
 

I recently picked up the python mastery bundle from humble bundle and one of the books (about larger-scale projects) has its exercises built around using anaconda virtual environments. I am able to create a project using:

% conda create -n project0 —channel=conda-forge python=3.12

But when I try to activate project0 I get an error that “activate” is an invalid choice. When I tried to initialize conda for Bash, my terminal behaved like the default echo for typed characters turned off.

136
 
 

So, you're an advanced beginner ...

137
 
 

Found via Planet Python

138
8
submitted 8 months ago* (last edited 8 months ago) by [email protected] to c/python
 
 

Hello,

I made a simple script to scraper threads.net using python and selenium. the script is just few lines long and it's easy to understand.

So what this script does?

first it will open edge browser(which you can change it to firefox or chrome). now you have to enter credentials to log into it. your browsing data and credentials will be stored in user_data which you can move around.

It scroll through threads's feed/hashtag/explore and It will store the src of every image it encounters so at the end we will have a links.txt file containing all the links to the images we have encountered.

now we have links.txt and we can use the following command to download all the images from the links.txt

wget -i links.txt

the script:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.options import Options
import time

options = Options()
options.add_argument("--user-data-dir=user_data")

driver = webdriver.Edge(options=options)

driver.get('https://threads.net')

s = set()

input("Press any key to continue...")
for i in range(30):
    try:
        elements = driver.find_elements(By.XPATH, "//img")
        for e in elements:
            s.add(e.get_attribute("src"))
        driver.execute_script("window.scrollBy(0, 1000);")
        time.sleep(0.2)
    except:
        print("oopsie")

with open("links.txt", 'w') as f:
    links = list(s)
    for l in links:
        f.write(l+"\n")

driver.quit()

I hope it was usefull :D

Edit: here is a link to links.txt https://0x0.st/HGjx.txt

139
 
 

Big update to rye is out: 0.18.0. Lots of bug fixes, lock files with source references for better docker support, global Python shims now pick up .python-version, automatic venv recreation on move. https://github.com/mitsuhiko/rye/discussions/544

via https://hachyderm.io/@mitsuhiko/111790331145932934

140
40
Python 3.13.0 alpha 3 is now available (pythoninsider.blogspot.com)
submitted 9 months ago by mac to c/python
141
 
 

cross-posted from: https://lemmy.ml/post/10682032

I've been looking to create a local database of cooking recipes for personal use, but doing it manually is quite tedious, to say the least. It takes maybe 5-ish minutes per recipe to navigate the various websites copy the text, create file, re-format the inevitably flawed text into readable ASCII only, and look over the result for spelling, grammar, and readability errors (one guy who made the recipes was seemingly barely literate, could hardly pass 3rd grade English class).

Are there any utilities you are aware of that would make this easier? Obviously the more automated the better, but automating text-pulling from a website, line sizing, indents, list formatting, and easy headers would be the minimum to be "worth it". Useful features would be automated file creation and naming, savable config presets, unified functionality (I.E. one utility that does everything, rather than a web API, a reformatter, and a file-writer, for example). The recipes tend to be in a certain format (Rich text? not sure) that prevents much of the readability from being retained when copied and pasted manually.

I'm looking for one single utility if at all possible, due to not wanting excessive headaches on my end. I'm running Linux Mint. Thanks for the heads-up.

142
143
 
 

I have this XML

<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="0.50.2 (823bef54)" openSubsonic="true"><searchResult3><song id="3b9d81b5def61a60705b9b89611a217f" parent="03693dd7b835740421cc1d6a4da201f3" isDir="false" title="Good Day featuring ScHoolboy Q" album="I Am &gt; I Was" artist="21 Savage" track="11" year="2018" genre="Rap" coverArt="mf-3b9d81b5def61a60705b9b89611a217f_5c1d3668" size="9716623" contentType="audio/mpeg" suffix="mp3" duration="242" bitRate="320" path="21 Savage/I Am &gt; I Was/11 - Good Day featuring ScHoolboy Q.mp3" created="2024-01-08T16:40:53.026754212Z" albumId="03693dd7b835740421cc1d6a4da201f3" artistId="1ae1d36568c651d53f78f427f05e9766" type="music" isVideo="false" bpm="0" comment=""><genres name="Rap"></genres></song></searchResult3></subsonic-response>

Which I got from an API call

I would like to be able to interact with it so I can check the artist and then pull the id

I thought this would be as simple as calling a key on an array (wrong terminology I know. Dict?), how wrong was I?

Having done some searching, I'm in the process of figuring out how xml.etree.ElementTree works. But it feels so overly complicated for what I'm trying to do? Am I going down the wrong path?

144
6
submitted 9 months ago* (last edited 9 months ago) by [email protected] to c/python
 
 

****FIXED IT! ****

    if "TXXX:FMPS_Rating_Amarok_Score" in tags:
      rating = tags["TXXX:FMPS_Rating_Amarok_Score"]
      print([key for key in rating])
    else:
      print(" ".join(["No rating exists for",mp3_file,"this song"]))

This code snippet prints the key as ['0.66'] That 0.66 is the exact value that I need?

A searching the internet showed me that people often want this the other way round, but no one seems to try to do what I'm doing? Does anyone have any idea on how to do it?

145
 
 

In my file, I have

from mutagen.id3 import ID3
tags = ID3(mp3_file)

Now if I do print(tags.keys())

It informs me that there's a TXXX:FMPS_Rating_Amarok_Score

But when I attempt to print(tags["TXXX:FMPS_Rating_Amarok_Score"])

It says there's a KeyError. What am I doing wrong?

146
48
Python 3.13 gets a JIT (tonybaloney.github.io)
submitted 9 months ago by [email protected] to c/python
147
 
 

cross-posted from: https://beehaw.org/post/10863052

Noob question incoming, thanks in advance for any help with this!

I have a specific use case in which I want to send an automated email or text to myself once a day (the message is different each time--otherwise I would just set an alarm, lol!). I'm running Pop_OS on an old desktop computer. Where I'm stuck is getting an email to successfully send from the command line. I'm looking for easy-to-follow instructions that would help me do that, and none of the articles or videos I've come across thus far have helped.

I'm aware of Twilio and other services that send SMS messages, but I'm looking for something free. Especially since I only need to text one person (myself), and infrequently at that.

Below is my attempt to send an email with the telnet command. Nothing ever came through...

XXXXXXXX@pop-os:~$ telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 pop-os ESMTP Exim 4.95 Ubuntu Sun, 07 Jan 2024 15:12:28 -0500
HELO gmail.com
250 pop-os Hello localhost [::1]
mail from: [email protected]
250 OK
rcpt to: [email protected]
250 Accepted
data
354 Enter message, ending with "." on a line by itself
Subject: Test
Body: Is this working?
.
250 OK id=1rMZW4-0002dj-Uy
quit
148
149
7
Python Rgonomics | Emily Riederer (emilyriederer.netlify.app)
submitted 9 months ago* (last edited 9 months ago) by ericjmorey to c/python
 
 

cross-posted from: https://programming.dev/post/8257343

Emily Riederer Writes:

Switching languages is about switching mindsets - not just syntax. New developments in python data science toolings, like polars and seaborn’s object interface, can capture the ‘feel’ that converts from R/tidyverse love while opening the door to truly pythonic workflows

Just to be clear:

  • This is not a post about why python is better than R so R users should switch all their work to python
  • This is not a post about why R is better than python so R semantics and conventions should be forced into python
  • This is not a post about why python users are better than R users so R users need coddling
  • This is not a post about why R users are better than python users and have superior tastes for their toolkit
  • This is not a post about why these python tools are the only good tools and others are bad tools

The Stack

WIth that preamble out of the way, below are a few recommendations for the most ergonomic tools for getting set up, conducting core data analysis, and communication results.

To preview these recommendations:

Set Up

Analysis

Communication

Miscellaneous

  • Environment Management: pdm
  • Code Quality: ruff

Read Python Rgonomics

150
view more: ‹ prev next ›