Exception handling approach
Which is better?
Approach 1:
def fun1():
if ...:
raise Exception()
return ...
def fun2():
fun1()
def main():
try:
fun2()
except Exception as error:
...
if __name__ == "__main__":
main()
Approach 2:
def fun1():
if ...:
raise Exception()
return ...
def fun2():
try:
fun1()
except Exception as error:
...
def main():
fun2()
if __name__ == "__main__":
main()
/r/Python
https://redd.it/1dv6p1c
Which is better?
Approach 1:
def fun1():
if ...:
raise Exception()
return ...
def fun2():
fun1()
def main():
try:
fun2()
except Exception as error:
...
if __name__ == "__main__":
main()
Approach 2:
def fun1():
if ...:
raise Exception()
return ...
def fun2():
try:
fun1()
except Exception as error:
...
def main():
fun2()
if __name__ == "__main__":
main()
/r/Python
https://redd.it/1dv6p1c
Reddit
From the Python community on Reddit
Explore this post and more from the Python community
Implementing MultiModal RAG Projects for PDFs with Critical Information in Tables
A common use-case of Python projects in production is for RAG applications. RAG deals with retrieval of relevant information from external data sources (often large in size) and combining them with user prompts to refine LLM responses.
Traditional RAG systems primarily use and parse text. But they often struggle with important details within tables. This hampers their utility in use-cases which demand reliability and accuracy such as RAG with Financial Documents. This is addressed with models like GPT-4o, Claude-3.5 Sonnet, LLaVA, which understand both text and images.
# Improving RAG accuracy for data in tables
Here we extract tables as images during the parsing process using GPT-4o, our choice of model for this blog with code. GPT-4o explains the content of the table in detail. Later it saves the table content with the document chunk into the index, making it easily searchable. The Pathway pipeline used here is scalable and great at incremental indexing โ i.e. it becomes useful when there are any changes expected in the data stored within PDFs or tables.
# Architecture Used for Multimodal RAG for PDFs
This architecture must efficiently manage data ingestion, processing, and querying, while providing accurate and timely responses to user queries. Key components include
/r/Python
https://redd.it/1dv7quy
A common use-case of Python projects in production is for RAG applications. RAG deals with retrieval of relevant information from external data sources (often large in size) and combining them with user prompts to refine LLM responses.
Traditional RAG systems primarily use and parse text. But they often struggle with important details within tables. This hampers their utility in use-cases which demand reliability and accuracy such as RAG with Financial Documents. This is addressed with models like GPT-4o, Claude-3.5 Sonnet, LLaVA, which understand both text and images.
# Improving RAG accuracy for data in tables
Here we extract tables as images during the parsing process using GPT-4o, our choice of model for this blog with code. GPT-4o explains the content of the table in detail. Later it saves the table content with the document chunk into the index, making it easily searchable. The Pathway pipeline used here is scalable and great at incremental indexing โ i.e. it becomes useful when there are any changes expected in the data stored within PDFs or tables.
# Architecture Used for Multimodal RAG for PDFs
This architecture must efficiently manage data ingestion, processing, and querying, while providing accurate and timely responses to user queries. Key components include
/r/Python
https://redd.it/1dv7quy
Reddit
From the Python community on Reddit: Implementing MultiModal RAG Projects for PDFs with Critical Information in Tables
Explore this post and more from the Python community
Module import error on PythonAnywhere
Server runs fine locally.
Uploaded app.py to /mysite
Created a virtual env and installed all dependencies using
updated /.virtualenvs/your-virtualenv-name under Web tab
running the file and getting ModuleNotFoundError: No module named 'dotenv'
when running the server from the bash console it runs fine
tried different combos of python versions but no luck
have been trying to work this out for hours and no luck
any ideas?
/r/flask
https://redd.it/1dvdwkb
Server runs fine locally.
Uploaded app.py to /mysite
Created a virtual env and installed all dependencies using
pip install Flask geopy openai Pillow python-dotenv rembg requestspip list suggests they installed just fineupdated /.virtualenvs/your-virtualenv-name under Web tab
running the file and getting ModuleNotFoundError: No module named 'dotenv'
when running the server from the bash console it runs fine
tried different combos of python versions but no luck
have been trying to work this out for hours and no luck
any ideas?
/r/flask
https://redd.it/1dvdwkb
Reddit
From the flask community on Reddit
Explore this post and more from the flask community
flpc: Probably the fastest regex library for Python. Made with Rust ๐ฆ and PyO3
With version 2 onwards, it introduces caching which boosted from 143x (no cache before v2) to \~5932.69x [max recorded performance on *my machine (not a NASA PC okay) a randomized string ASCII + number string\] (cached - lazystatic, sometimes \~1300x on first try) faster than the re-module on average. The time is calculated in milliseconds. If you find any ambiguity or bug in the code, Feel free to make a PR. I will review it. You will get max performance via installing via pip
There are some things to be considered:
1. The project is not written with a complete drop-in replacement for the re-module. However, it follows the same naming system or API similar to re.
2. The project may contain bugs especially the benchmark script which I haven't gone through properly.
3. If your project is limited to resources (maybe running on Vercel Serverless API), then it's not for you. The wheel file is around 700KB to 1.1 MB and the source distribution is 11.7KB
https://github.com/itsmeadarsh2008/flpc
*Python3
/r/Python
https://redd.it/1dv811q
With version 2 onwards, it introduces caching which boosted from 143x (no cache before v2) to \~5932.69x [max recorded performance on *my machine (not a NASA PC okay) a randomized string ASCII + number string\] (cached - lazystatic, sometimes \~1300x on first try) faster than the re-module on average. The time is calculated in milliseconds. If you find any ambiguity or bug in the code, Feel free to make a PR. I will review it. You will get max performance via installing via pip
There are some things to be considered:
1. The project is not written with a complete drop-in replacement for the re-module. However, it follows the same naming system or API similar to re.
2. The project may contain bugs especially the benchmark script which I haven't gone through properly.
3. If your project is limited to resources (maybe running on Vercel Serverless API), then it's not for you. The wheel file is around 700KB to 1.1 MB and the source distribution is 11.7KB
https://github.com/itsmeadarsh2008/flpc
*Python3
/r/Python
https://redd.it/1dv811q
GitHub
GitHub - itsmeadarsh2008/flpc: A Rust-based regex crate wrapper for Python3 to get faster performance. ๐พ
A Rust-based regex crate wrapper for Python3 to get faster performance. ๐พ - itsmeadarsh2008/flpc
Help with SQLAlchemy
Hi everyone,
I am new o flask and I would like some help to make this sql to work on Flask.
When I run this on mysql I got the results I want:
select t.date, t.name from
inner join (
select name, max(date) as MaxDate
from
tm on t.name = tm.name and t.date = tm.MaxDate;
this is my code thats is working but showing all the lines.
# Creating Models
class Block(db.Model):
tablename = "allflashdev"
index = db.Column(db.Date, nullable=False, unique=True, primarykey=True)
date = db.Column(db.Date, nullable=False)
name = db.Column(db.String(45), nullable=False)
raw = db.Column(db.String(45), nullable=False)
free = db.Column(db.String(45), nullable=False)
frep = db.Column(db.String(45), nullable=False)
util = db.Column(db.String(45), nullable=False)
utip = db.Column(db.String(45), nullable=False)
def
/r/flask
https://redd.it/1dvd2aj
Hi everyone,
I am new o flask and I would like some help to make this sql to work on Flask.
When I run this on mysql I got the results I want:
select t.date, t.name from
capacitydata.allflash_dev tinner join (
select name, max(date) as MaxDate
from
capacitydata.allflash_dev group by name)tm on t.name = tm.name and t.date = tm.MaxDate;
this is my code thats is working but showing all the lines.
# Creating Models
class Block(db.Model):
tablename = "allflashdev"
index = db.Column(db.Date, nullable=False, unique=True, primarykey=True)
date = db.Column(db.Date, nullable=False)
name = db.Column(db.String(45), nullable=False)
raw = db.Column(db.String(45), nullable=False)
free = db.Column(db.String(45), nullable=False)
frep = db.Column(db.String(45), nullable=False)
util = db.Column(db.String(45), nullable=False)
utip = db.Column(db.String(45), nullable=False)
def
/r/flask
https://redd.it/1dvd2aj
Reddit
From the flask community on Reddit
Explore this post and more from the flask community
D Gave ML Framework Codesignal Test and beyond devastated!
I just gave the CodeSignal ML framework test after a lot of preparation, and it felt like I was trying way too hard to write ML algorithm code that I'm well versed with. I know the concepts in detail for all the algorithms, but writing two algorithms from scratch in 70 minutes, including one more coding task plus 6 MCQ questions and one output, is tough.
I'm not sure if it's just me facing this challenge or if it's common. It was very hard to recall all the functions (the logic is easy) to write the code in that stressful, proctored environment. How can I get better at this? I know practice, practice, practice, but even that didn't seem to help here. And I didn't find any practice materials to stimulate the same environment. If you know something please share.
Isn't this too much of an expectation? I'm just getting done with my PhD and at times, I feel like looking for a job is more stressful than it ever was (I have 5 years of experience). The expectations are too high. How are you all coping with such a rat race?
/r/MachineLearning
https://redd.it/1dvhwk3
I just gave the CodeSignal ML framework test after a lot of preparation, and it felt like I was trying way too hard to write ML algorithm code that I'm well versed with. I know the concepts in detail for all the algorithms, but writing two algorithms from scratch in 70 minutes, including one more coding task plus 6 MCQ questions and one output, is tough.
I'm not sure if it's just me facing this challenge or if it's common. It was very hard to recall all the functions (the logic is easy) to write the code in that stressful, proctored environment. How can I get better at this? I know practice, practice, practice, but even that didn't seem to help here. And I didn't find any practice materials to stimulate the same environment. If you know something please share.
Isn't this too much of an expectation? I'm just getting done with my PhD and at times, I feel like looking for a job is more stressful than it ever was (I have 5 years of experience). The expectations are too high. How are you all coping with such a rat race?
/r/MachineLearning
https://redd.it/1dvhwk3
Reddit
From the MachineLearning community on Reddit
Explore this post and more from the MachineLearning community
Need a buddy / mentor to work with and become good in django
Hello there. I'm a 3rd yr engineering student. I'm quite decent in python (i started off before my first year). later near the end of 1st year i picked up django, got grasp of the basics from YT.
At the start of 2nd year i picked up the book Django for Beginners By William vincent and got halfway through it but had to focus on academics to had to put it aside a bit. by the end of 2nd year i finished the book and got familiar with all the things like CRUD, Forms, User accounts, Password change/reset etc (although i'd need a quick recap cause its been a month or two since then). i did manually code side by side all the apps in the book and have it on my github so i have quite a good idea about how it works. but i think you cant really get the actual grasp of it unless you work on some real projects. Read that book like 2 times though
So i'm looking for someone who is good in django or is working on a project and is willing to mentor me while letting me help with the project too.
Hope you're
/r/django
https://redd.it/1dva7ng
Hello there. I'm a 3rd yr engineering student. I'm quite decent in python (i started off before my first year). later near the end of 1st year i picked up django, got grasp of the basics from YT.
At the start of 2nd year i picked up the book Django for Beginners By William vincent and got halfway through it but had to focus on academics to had to put it aside a bit. by the end of 2nd year i finished the book and got familiar with all the things like CRUD, Forms, User accounts, Password change/reset etc (although i'd need a quick recap cause its been a month or two since then). i did manually code side by side all the apps in the book and have it on my github so i have quite a good idea about how it works. but i think you cant really get the actual grasp of it unless you work on some real projects. Read that book like 2 times though
So i'm looking for someone who is good in django or is working on a project and is willing to mentor me while letting me help with the project too.
Hope you're
/r/django
https://redd.it/1dva7ng
Reddit
From the django community on Reddit
Explore this post and more from the django community
Friday Daily Thread: r/Python Meta and Free-Talk Fridays
# Weekly Thread: Meta Discussions and Free Talk Friday ๐๏ธ
Welcome to Free Talk Friday on /r/Python! This is the place to discuss the r/Python community (meta discussions), Python news, projects, or anything else Python-related!
## How it Works:
1. Open Mic: Share your thoughts, questions, or anything you'd like related to Python or the community.
2. Community Pulse: Discuss what you feel is working well or what could be improved in the /r/python community.
3. News & Updates: Keep up-to-date with the latest in Python and share any news you find interesting.
## Guidelines:
All topics should be related to Python or the /r/python community.
Be respectful and follow Reddit's Code of Conduct.
## Example Topics:
1. New Python Release: What do you think about the new features in Python 3.11?
2. Community Events: Any Python meetups or webinars coming up?
3. Learning Resources: Found a great Python tutorial? Share it here!
4. Job Market: How has Python impacted your career?
5. Hot Takes: Got a controversial Python opinion? Let's hear it!
6. Community Ideas: Something you'd like to see us do? tell us.
Let's keep the conversation going. Happy discussing! ๐
/r/Python
https://redd.it/1dvkvjp
# Weekly Thread: Meta Discussions and Free Talk Friday ๐๏ธ
Welcome to Free Talk Friday on /r/Python! This is the place to discuss the r/Python community (meta discussions), Python news, projects, or anything else Python-related!
## How it Works:
1. Open Mic: Share your thoughts, questions, or anything you'd like related to Python or the community.
2. Community Pulse: Discuss what you feel is working well or what could be improved in the /r/python community.
3. News & Updates: Keep up-to-date with the latest in Python and share any news you find interesting.
## Guidelines:
All topics should be related to Python or the /r/python community.
Be respectful and follow Reddit's Code of Conduct.
## Example Topics:
1. New Python Release: What do you think about the new features in Python 3.11?
2. Community Events: Any Python meetups or webinars coming up?
3. Learning Resources: Found a great Python tutorial? Share it here!
4. Job Market: How has Python impacted your career?
5. Hot Takes: Got a controversial Python opinion? Let's hear it!
6. Community Ideas: Something you'd like to see us do? tell us.
Let's keep the conversation going. Happy discussing! ๐
/r/Python
https://redd.it/1dvkvjp
Redditinc
Reddit Rules
Reddit Rules - Reddit
How stable is Supabase when used with Django?
Is it stable enough to use as a main DB on Django? is there any speed or performance issue when used on Django? Please share your experience with Supbase. I see that Supabase is becoming popular everyday.
/r/django
https://redd.it/1dvmk64
Is it stable enough to use as a main DB on Django? is there any speed or performance issue when used on Django? Please share your experience with Supbase. I see that Supabase is becoming popular everyday.
/r/django
https://redd.it/1dvmk64
Reddit
From the django community on Reddit
Explore this post and more from the django community
django outstanding token
hello, how the rest_framework_simplejwt in django suppose to be stateless and when i use rest_framework_simplejwt.token_blacklist to logout the user and put in the blacklist, it create an outstanding token table in the database and store the non expired tokens.
/r/django
https://redd.it/1dvk3dr
hello, how the rest_framework_simplejwt in django suppose to be stateless and when i use rest_framework_simplejwt.token_blacklist to logout the user and put in the blacklist, it create an outstanding token table in the database and store the non expired tokens.
/r/django
https://redd.it/1dvk3dr
Reddit
From the django community on Reddit
Explore this post and more from the django community
Tips for learning rest framework
So I'm starting to learn REST framework and need some advice. I'm new to backend development, so can anyone give me advice on how to start, how long it might take, best practices, and what I should focus on?
/r/django
https://redd.it/1dvb9yj
So I'm starting to learn REST framework and need some advice. I'm new to backend development, so can anyone give me advice on how to start, how long it might take, best practices, and what I should focus on?
/r/django
https://redd.it/1dvb9yj
Reddit
From the django community on Reddit
Explore this post and more from the django community
My first gui app (youtube to mp3)
What my project does : Download youtube mp4 video and convert them to mp3.
Target audience : E for everyone.
Comparison : My app has a youtube page integrated in it for ease of use.
Do you guys have some improvement that could be done to the code?
check out the project : https://gitlab.com/sand0ftime1/tube2mp3
I want to make the progress bar work at the same time as the download and also i have some bugs in the todo list.
/r/Python
https://redd.it/1dvltza
What my project does : Download youtube mp4 video and convert them to mp3.
Target audience : E for everyone.
Comparison : My app has a youtube page integrated in it for ease of use.
Do you guys have some improvement that could be done to the code?
check out the project : https://gitlab.com/sand0ftime1/tube2mp3
I want to make the progress bar work at the same time as the download and also i have some bugs in the todo list.
/r/Python
https://redd.it/1dvltza
GitLab
Sands0ft / tube2mp3 ยท GitLab
Storing the password safely
Hello ,
In my project, First the User fill out the register form including password for his account. This data is stored in temporary database. Secondly , If the admin approves him, he/she is registered as user. I am using CustomUser and Custom usermanager. The password which i am saving in temporary database when a user submit form is in plain format. And when the admin approves, it get hashed. I want to store hashed password in temporary database as well. When i use inbuilt mechanisms like make_password, the password get hashed twice , while storing in temp. database and also while storing in Custom User database. How to solve this problem ? I want to hash or secure the password in temp. database while being able to login /logout /authenticate ?
/r/django
https://redd.it/1dvv06l
Hello ,
In my project, First the User fill out the register form including password for his account. This data is stored in temporary database. Secondly , If the admin approves him, he/she is registered as user. I am using CustomUser and Custom usermanager. The password which i am saving in temporary database when a user submit form is in plain format. And when the admin approves, it get hashed. I want to store hashed password in temporary database as well. When i use inbuilt mechanisms like make_password, the password get hashed twice , while storing in temp. database and also while storing in Custom User database. How to solve this problem ? I want to hash or secure the password in temp. database while being able to login /logout /authenticate ?
/r/django
https://redd.it/1dvv06l
Reddit
From the django community on Reddit
Explore this post and more from the django community