1
30
Python Insider: Python 3.12.4 released (pythoninsider.blogspot.com)
2
105
Python 3.12.0 (www.python.org)
3
33
Welcome to c/Python! (programming.dev)

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.

4
11

Hi, I want to know what is the best way to keep the databases I use in different projects? I use a lot of CSVs that I need to prepare every time I'm working with them (I just copy paste the code from other projects) but would like to make some module that I can import and it have all the processes of the databases for example for this database I usually do columns = [(configuration of, my columns)], names = [names], dates = [list of columns dates], dtypes ={column: type},

then database_1 = pd.read_fwf(**kwargs), database_2 = pd.read_fwf(**kwargs), database_3 = pd.read_fwf(**kwargs)...

Then database = pd.concat([database_1...])

But I would like to have a module that I could import and have all my databases and configuration of ETL in it so I could just do something like 'database = my_module.dabase' to import the database, without all that process everytime.

Thanks for any help.

5
2

This happens if I use set_time or set_position. Is this typical, or am I just not doing it right?

This is on a Pi Zero 2 W, so not the most powerful, but should be able to handle this.

These are the relevant bits of how I'm setting up the player:

    self._vlc = vlc.Instance()
    self._player = self._vlc.media_player_new()
    self._list_player = self._vlc.media_list_player_new()
    self._list_player.set_media_player(self._player)

    playlist = self._vlc.media_list_new()
    for index in self._play_order:
      playlist.add_media(self._vlc.media_new_path(self._songs[index]))

    self._list_player.stop()
    self._list_player.set_media_list(playlist)
    self._list_player.play()

And trying to seek is just this:

    self._player.set_time(_s_to_ms(seconds))

Any ideas would be greatly appreciated!

6
15
submitted 8 hours ago* (last edited 7 hours ago) by librejoe@lemmy.world to c/python@programming.dev

I'm new to programming a bit, and am learning python so I can learn flask, using the python crash course book. I was learning about list comprehension but it briefly talks about it. If I do

list[list.append(value) for value in range(1, 20)]

it doesn't work. Would this be some sort of recursive expression that is not possible?

7
17

Hi,

I have to interface with systems that use iso-8859-x encoding (not by choice...), and I'm surprised that the following doesn't throw an error:

>>> str(bytes(range(256)), encoding="iso-8859-1", errors="strict")
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0¡¢£¤¥¦§¨©ª«¬\xad®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ'

Bytes in the 0x80—0x9f range are not valid iso-8859-1, and I was expecting the above to raise a DecodeError of some sort; instead it looks like those are passed through.

I'm perfectly happy with this behaviour, I would like to make sure I can depend on it. Can I take an arbitrary byte buffer, decode as ISO-8859-1, and never get any error? Is it guaranteed to be lossless ?

8
34

So, I have a python script I'd like to run from time to time from the CLI (on Linux) that resides inside a venv. What's the recommended/intended way to do this?
Write a wrapper shell script and put it inside a $PATH-accessible directory that activates the virtual environment, runs the python script and deactivates the venv again? This seems a bit convoluted, but I can't think of a better way.

9
15
10
126
11
36
submitted 1 week ago* (last edited 1 week ago) by riklaunim@programming.dev to c/python@programming.dev
12
73
13
30

I started working through the 100 Days of Code course of Udemy last February, and I'm in the home stretch. I'm on the final lessons, which are really just prompts for projects. No hand holding, just a brief description of the goal. I recently finished a tkinter GUI program, the goal of which was to enable adding text watermarks.

I took a few liberties--mainly, I made it possible to layer a png on top of the background. It was a really fun project and quickly grew more complicated than I expected it to. I got some hands on experience with the Single Responsibility Principle, as I started off doing everything in my Layout class.

Eventually, I moved all the stuff that actually involved manipulating the Image objects to an ImageManager class. I feel like I could have gotten even more granular. That's one thing I would love to get some feedback on. How would a more experienced programmer have architected this program?

Anyway, I guess this preamble is long enough. I'm going to leave a link to the repository here. I would have so much appreciation for anyone who took the time to look at the code, or even clone the repo and see if my instructions for getting it to run on your machine work.

Watermark GUI Repo

14
43

I'm currently learning Python and am learning about very basic functions such as int(), float(), and input().

I have the first two down pat, but I'm struggling to understand the last. The example I'm looking at is found at 12:26 of this video:

nam = input('Who are you? ')
print('Welcome', nam)

Who are you? Chuck
Welcome Chuck

In this case, wouldn't nam be a variable equal to the text on the right side of the = sign?

In which case, if nam is equal to input('Who are you? '), then wouldn't print('Welcome', nam) just result in

Welcome input(Who are you? )?

Obviously not (nor does it work in a compiler), which leads me to believe I'm clearly misunderstanding something. But I've rewatched that section of the video several times, and looked it up elsewhere on the web, and I just can't wrap my head around it.

Could someone help me with this?

Thanks.

15
24

If I run this

#!/bin/bash

ARCH=$(python fetch_architecture.py)
if [ $ARCH == "aarch64" -o $ARCH == "armv71" ] ; then
    export PATH=/opt/local/llvm/bin:${PATH}
    cd /app
    RUSTFLAGS="-C linker=lld" wasm-pack build --target web --release plume-front
else
    wasm-pack build --target web --release plume-front
fi

via the terminal, it works just fine. But when I run it via the Dockerfile,

COPY . . 
RUN cargo install wasm-pack 
RUN chmod a+x ./script/plume-front.sh 
RUN sleep 1 
RUN ./script/plume-front.sh

It says python: command not found and then [: too many arguments

16
21
What Git library to choose? (discuss.tchncs.de)

I happen to write a lot of python code dealing with git repositories. Currently I am calling the git command line tool from python and interpret the output.

This solution really doesn't scale well. Can you recommend a python library that wraps git functionality?

I have found three:

  • GitPython: Seems to work well, but it is in maintenance mode, unlikely to be improved. It also does not have any type hints making working with it annoying.
  • pygit2: Seems well supported and has type hints. But it also seems very low level and pretty tedious to use.
  • dulwich: Looks very promising feature wise but I'm unsure how well it is supported. It seems like an ambitious project being largely done by just one person.
17
26
18
42
submitted 1 month ago by mao@lemmy.sdf.org to c/python@programming.dev

Neato

19
28
20
28
Python beginner (feddit.uk)

Good evening, everyone. I have, but one quick inquiry. What are the best resources in your opinion to learn python by yourself as a complete beginner? Thank you all

21
7
submitted 1 month ago* (last edited 1 month ago) by thingsiplay@beehaw.org to c/python@programming.dev

Solved: Thanks to a user with this reply: https://programming.dev/comment/10034690


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

Hi all. I have a little problem and don't know how to solve. A CLI program in Python is broken since Python 3.12. It was working in Python 3.11. The reason is, that Python 3.12 changed how subclassing of a pathlib.Path works (basically fixed an issue), which now breaks a workaround.

The class in question is:

class File(PosixPath):
    def __new__(cls, *args: Any, **kwargs: Any) -> Any:
        return cls._from_parts(args).expanduser().resolve()  # type: ignore

    def __init__(self, source: str | Path, *args: Any) -> None:
        super().__init__()
        self.__source = Path(source)

    @property
    def source(self) -> Path:
        return self.__source

    @property
    def modified(self) -> Time:
        return Time.fromtimestamp(os.path.getmtime(self))

    @property
    def changed(self) -> Time:
        return Time.fromtimestamp(os.path.getctime(self))

    @property
    def accessed(self) -> Time:
        return Time.fromtimestamp(os.path.getatime(self))

    # Calculate sha512 hash of self file and compare result to the
    # checksum found in given file. Return True if identical.
    def verify_sha512(self, file: File, buffer_size: int = 4096) -> bool:
        compare_hash: str = file.read_text().split(" ")[0]
        self_hash: str = ""
        self_checksum = hashlib.sha512()
        with open(self.as_posix(), "rb") as f:
            for chunk in iter(lambda: f.read(buffer_size), b""):
                self_checksum.update(chunk)
            self_hash = self_checksum.hexdigest()
        return self_hash == compare_hash

and I get this error when running the script:

Traceback (most recent call last):
File "/home/tuncay/.local/bin/geprotondl", line 1415, in 
sys.exit(main())
^^^^^^
File "/home/tuncay/.local/bin/geprotondl", line 1334, in main
arguments, status = parse_arguments(argv)
^^^^^^^^^^^^^^^^^^^^^
File "/home/tuncay/.local/bin/geprotondl", line 1131, in parse_arguments
default, status = default_install_dir()
^^^^^^^^^^^^^^^^^^^^^
File "/home/tuncay/.local/bin/geprotondl", line 1101, in default_install_dir
steam_root: File = File(path)
^^^^^^^^^^
File "/home/tuncay/.local/bin/geprotondl", line 97, in __new__
return cls._from_parts(args).expanduser().resolve()  # type: ignore
^^^^^^^^^^^^^^^
AttributeError: type object 'File' has no attribute '_from_parts'. Did you mean: '_load_parts'?

Now replacing _from_parts with _load_parts does not work either and I get this message in that case:

Traceback (most recent call last):
File "/home/tuncay/.local/bin/geprotondl", line 1415, in 
sys.exit(main())
^^^^^^
File "/home/tuncay/.local/bin/geprotondl", line 1334, in main
arguments, status = parse_arguments(argv)
^^^^^^^^^^^^^^^^^^^^^
File "/home/tuncay/.local/bin/geprotondl", line 1131, in parse_arguments
default, status = default_install_dir()
^^^^^^^^^^^^^^^^^^^^^
File "/home/tuncay/.local/bin/geprotondl", line 1101, in default_install_dir
steam_root: File = File(path)
^^^^^^^^^^
File "/home/tuncay/.local/bin/geprotondl", line 97, in __new__
return cls._load_parts(args).expanduser().resolve()  # type: ignore
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/pathlib.py", line 408, in _load_parts
paths = self._raw_paths
^^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute '_raw_paths'

I have searched the web and don't understand how to fix this. Has anyone an idea what to do?

22
51

Trey Hunner writes:

This article is primarily meant to act as a Python time complexity cheat sheet for those who already understand what time complexity is and how the time complexity of an operation might affect your code. For a more thorough explanation of time complexity see Ned Batchelder's article/talk on this subject.

Read Python Big O: the time complexities of different data structures in Python

23
36
24
9

I have a Keybow MINI hooked up to a Raspberry Pi Zero W, and I'm using Python to respond to events. I have one button that kicks off playing a song on a passive buzzer, and I'm wondering if there's a way to have a button press stop the song before it completes.

25
10

Many commertial apps have options to run apps at logins... Is there any cross-platform way to do so in python?

view more: next ›

Python

5878 readers
63 users here now

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

📅 Events

October 2023

November 2023

PastJuly 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS