26
12
submitted 1 month ago* (last edited 1 month ago) by SpongeB0B@programming.dev to c/python@programming.dev

Hi,

I use gunicorn in my venv

I have quite few venv that run gunicorn.

I would like to reuse gunicorn for other venv

I launch my web application like this

#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.

27
25
Convert HEIC to JPG (www.slyautomation.com)
submitted 1 month ago by slyuser@lemmy.ml to c/python@programming.dev
28
13
submitted 1 month ago* (last edited 1 month ago) by batmaniam@lemmy.world to c/python@programming.dev

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!

29
60
30
39
31
15
submitted 1 month ago by Zara@lemmy.ml to c/python@programming.dev

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 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.

32
33
submitted 1 month ago* (last edited 1 month ago) by Berin@discuss.tchncs.de to c/python@programming.dev

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

@renpy

#RenPy #GameDev #VNDev #IndieDev #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

33
31

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.

34
12
35
30
An HTMX success story (www.sheenaoc.com)
submitted 2 months ago by rimu@piefed.social to c/python@programming.dev

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

36
53
37
75
38
11
submitted 2 months ago by s12@sopuli.xyz to c/python@programming.dev

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?

39
5
submitted 2 months ago by slyuser@lemmy.ml to c/python@programming.dev

This is slyautomation and I am thrilled to welcome you to this in-depth tutorial where we will unravel the intricacies of training an aimbot using the cutting-edge YOLOv8.

40
45
41
26
42
14
43
9

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!

44
25
submitted 2 months ago by driving_crooner to c/python@programming.dev

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.

45
19
submitted 2 months ago* (last edited 2 months 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?

46
18

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 ?

47
35

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.

48
15
49
126
50
36
submitted 3 months ago* (last edited 3 months ago) by riklaunim@programming.dev to c/python@programming.dev
view more: ‹ prev next ›

Python

6219 readers
22 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