pythondaily | Education

Telegram-канал pythondaily - Python Daily

1102

Daily Python News Question, Tips and Tricks, Best Practices on Python Programming Language Find more reddit channels over at @r_channels

Subscribe to a channel

Python Daily

What are good resources for an intermediate programmer to learn more?

Im in between jobs right now and want to try and develop my skills. Should i work on trying to become an expert in specific libraries that are common or learn better habits for optimizing code? What resources would you recommend for someone who is pretty familiar with the core language?

/r/Python
https://redd.it/ytpdh9

Читать полностью…

Python Daily

instance folder is automatically created

While trying to create a database with the following code
from app import db
db.create_all()
the database is being created in the automatically created instance sub-dircetory, while in the tutorial I watched it is directly being created in the directory, the programme is running fine but why the difference.

On surfing the web I read that instance folder should not be added to the version control, so should I then not add my database to my GitHub repo.

/r/flask
https://redd.it/ytvds8

Читать полностью…

Python Daily

Django rest writable nested serializer

How to write and update nested serializer in drf. I have two models. Just an example below.

Class Account (models.Model):
name = models.charfield()
email = models.Emailfield()


Class user_profile(models.Model):
user = models.ForiegnKey(Account)
Addrs = models.Textfield()
Phone = models.Integerfield()

​

and how to write and update this. Also how to get `request.user` inside serializer?

and am using JWT authentication.

/r/django
https://redd.it/ytns6b

Читать полностью…

Python Daily

Weird Behavior When Prepopulating WTForms FieldList

Not sure if this is allowed but I'm just here to repost my own Stack Overflow question to look for possible responses here as well...

https://stackoverflow.com/questions/74416997/weird-behavior-when-prepopulating-fieldlist-wtforms

/r/flask
https://redd.it/ytmgc7

Читать полностью…

Python Daily

Run external programs intuitively in Python

Hi all!

It's the creator of [Rocketry](https://github.com/Miksus/rocketry), [Red Mail](https://github.com/Miksus/red-mail) and [Red Box](https://github.com/Miksus/red-box) again. This week I thought to make it easier to integrate command-line programs to your Python applications.

I came up with [Scriptor](https://github.com/Miksus/scriptor):

>>> from scriptor import Program
>>> python = Program("python3")
>>> python('myscript.py', report_date="2022-11-12")
"printed values"

What happened? The above ran the command:

`python3 myscript.py --report_date 2022-11-12`

and it returned whatever the program printed (in standard output aka. stdout).

So Scriptor makes it easy to integrate external programs or scripts written in other languages or in Python but using different Python interpreter.

For example, using Git is quite handy with it:

>>> from scriptor import Program
>>> git = Program('git')
>>> myrepo = git.use(cwd="path/to/myrepo")
>>> myrepo("log", n=2)
commit 07a865c3b7000324ce582fecb0ec24e3ef6203f1 (HEAD -> master, origin/master)
Author: Miksus <miksus@example.com>
Date: Wed Oct 5 00:20:00 2022 +0300

Fixed the thing.

commit 7ffda87524ddde698f5337f150b37fe07d74642f
Author: Miksus <miksus@example.com>
Date: Sat Oct

/r/Python
https://redd.it/ytehq3

Читать полностью…

Python Daily

Relative representations enable zero-shot latent space communication
https://openreview.net/forum?id=SrC-nwieGJ

/r/MachineLearning
https://redd.it/yt6slt

Читать полностью…

Python Daily

What is the best YouTube channel to learn django from?



/r/django
https://redd.it/ysz4la

Читать полностью…

Python Daily

D Question collection thread for Stability AI’s upcoming AMA on November 15

Hey Reddit, this is Nathan Lile with Stability AI. Emad and Team look forward to answering your questions in the upcoming AMA, scheduled for November 15 at 11:00 AM PST.

As u/olafnij said,

> [Stability AI] has been one of the driving forces behind the open-source AI movement, being known for being key in the success of [StableDiffusion](
https://www.reddit.com/r/StableDiffusion/) and many other disruptive changes to the overall landscape of AI.

This is the thread *before the official AMA* (referenced in the [pinned announcement post](
https://old.reddit.com/r/MachineLearning/comments/ypnujk/nstabilityaiamaonnovember15/)) to collect questions before the official AMA if you can’t attend live.

/r/MachineLearning
https://redd.it/ysmwvt

Читать полностью…

Python Daily

Add form input to list

I am attempting to take user input from a form field and add it to a list, but I am getting 'ImmutableMultiDict' object is not callable when try to do so. Any suggestion on how I can fix this?

tcsAshburn/Hangman-Online#main.py">My code

/r/flask
https://redd.it/ysm251

Читать полностью…

Python Daily

Do you test authentication in your views?

I have a view that creates a resource. Using this view is allowed only for authenticated users. In this case, should I be writing a test that checks that only authenticated users are allowed to call this view? I'm leaning towards not testing this because it is not strictly a business logic and that's what I'm aiming to test

/r/django
https://redd.it/ysi486

Читать полностью…

Python Daily

What is the main reason you write unit tests?

a. To find bugs
b. To prevent regressions in the future
c. To ensure interfaces match their specification

/r/Python
https://redd.it/ys9gsc

Читать полностью…

Python Daily

How to csutomize create view

I want to convert a class based view to have the same functionality as the function based view

@login_required
def add_tenant_save(request, is_staff=True):
if request.method != "POST":
return HttpResponseRedirect("Method Not Allowed")

else:
form=AddTenantForm(request.POST, request.FILES)
if form.is_valid():

# tenant = None
name = form.cleaned_data["name"]
tenant_slug = form.cleaned_data["slug"]
owner = form.cleaned_data["owner"]
#tenant_name = request.POST.get('name')
#tenant_slug =

/r/django
https://redd.it/ys9f43

Читать полностью…

Python Daily

R A relabelling of the COCO 2017 dataset

Hi everybody, here is the complete relabelling of the COCO 2017 dataset for segmentation. This is all free of charge, un-gated, and was done by Sama, a labelling company for CV data. The dataset is available on the Sama website under a Creative Commons license: https://www.sama.com/sama-coco-dataset/. I would also love to hear any feedback.
Disclaimer: I work for Sama

/r/MachineLearning
https://redd.it/yrfzcf

Читать полностью…

Python Daily

Is this tutorial Intro to Flask-WTF (Part 1 of 5) still good even though it is 5 years old? https://www.youtube.com/watch?v=vzaXBm-ZVOQ

https://www.youtube.com/watch?v=vzaXBm-ZVOQ

/r/flask
https://redd.it/yrxmpb

Читать полностью…

Python Daily

MicroPython officially becomes part of the Arduino ecosystem | Arduino Blog
https://blog.arduino.cc/2022/11/10/micropython-officially-becomes-part-of-the-arduino-ecosystem/

/r/Python
https://redd.it/yrldcw

Читать полностью…

Python Daily

Finally Pushed Myself to do Full DRF + React

I've always been a supporter of Keep it Simple Stupid and leveraging server-side rendering to the max but I've also felt like I needed to build a complete SPA as a side project.

Understand this is 100% in beta stage, but I'm pretty happy with this little thing: pagesauce.io

The premise is to be a better A/B testing app by being simple, fast-to-onboard, and smart. Facebook ads/pixel for any content on your website. Here's a thread explaining the use case a bit better than I am here: https://twitter.com/wolfofwebsites/status/1591459576196513793?s=20&amp;t=Me7tQot\_DpQBSOVzOXxy0w

I've attached quick video demo since I don't have a landing page or anything yet. I think I am gonna send it on Product Hunt in a couple weeks (if I can get some beta testers). I've got an email list for it if you feel so inclined. Or just go ahead and register \- I've got chat on there and would love to hear about all the bugs haha

&#x200B;

Edit: I also have zero intentions of attempting to charge anyone willing to beta test and mess with this thing. This is the first time I've implemented an embedded script like this and the nerd side of me is so satisfied - I just want

/r/django
https://redd.it/ytqkcd

Читать полностью…

Python Daily

Sunday Daily Thread: What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.

/r/Python
https://redd.it/ytmeap

Читать полностью…

Python Daily

Cleaning up panda dataframe calls
https://pyjanitor-devs.github.io/pyjanitor/

/r/IPython
https://redd.it/yti4z0

Читать полностью…

Python Daily

Lightweight Python DB that can hold arbitrary binary objects

I've been fiddling with some file sensor/watchdog type programs lately. I've tried messing around with pickleDB and tinyDB, but I'd really like to be able to find a lightweight database that I can store a binary object in as well. So things like zips, images, pickled python objects (which I thought pickledb would do)

Anyone have any ideas? Someone mentioned RocksDB but it didn't make sense to me, maybe I have to dig more into the documentation there?

/r/Python
https://redd.it/ytfzug

Читать полностью…

Python Daily

Starlite without Starlette

Howdy fellow travellers!

A little less than a month ago I wrote in this subreddit about our plans to drop Starlette as a core dependency of Starlite. After a lot of work, I am glad to say that this effort is now complete: Starlite 1.39.0 was released a few hours ago and Starlite no longer depends on Starlette. You can find the release notes here.

Some of you might wonder why this is news at all? Well for us its a big milestone - Starlite started out as an API framework competing with FastAPI using the same building blocks - Starlette and Pydantic. But Starlite grew and evolved, and it reached a point where it no longer made sense to continue to extend Starlette. The result is that Starlite is now a complete ASGI framework on its own accord, without dependning on any ASGI toolkit.

The name Starlite now carries a bit of history in it - you can see the readme of the library in Github which has a section discussing this.

As always I invite you all to discuss, and we are always looking for more contributors and maintainers!

You can find us on our discord server or in the

/r/Python
https://redd.it/yt94wb

Читать полностью…

Python Daily

This is how i got more performance in WebSockets than Node or Bun using Python

Bun is changing out the scenario for Node.js, with much more performance in HTTP and WebSockets, but how FAST it is compared with Python?
In the Bun website https://bun.sh/, the source code of the WebSocket benchmark is available, so... let's try to run Falcon + uvicorn on it!

I just simplified a little the benchmark, to remove a string concatenation, to measure more of the raw throughput with less impact other things, and runned using Falcon + uvicorn and socketify.py, when benchmarking i was talking with Vytautas Liuolia in the Falcon Gitter for tunning HTTP performance in other raw throughtput testing as well, and Falcon is not so much focused on WS performance, this also depends a lot of ASGI server too. For this test i choose uvicorn with gunicorn as ASGI server.

Messages per second with Linux x64:

https://raw.githubusercontent.com/cirospaciari/socketify.py/main/misc/ws-bar-graph.png

Socketify got almost 900k messages/s with PyPy3 and 860k with Python3 the same performance as Bun that also uses uWebSockets, Falcon at 35k messages/s and Falcon with PyPy3 improves into 56k messages/s, node.js manages 192k.

You can see the source code for the benchmark here https://github.com/cirospaciari/socketify.py/tree/main/bench
and if you have some time check out the github https://github.com/cirospaciari/socketify.py this project can be even better with some community

/r/Python
https://redd.it/yt3j70

Читать полностью…

Python Daily

What is the best Django Course / Youtube Playlist available to learn Django from ?

I just learnt some basics of python and was thinking of starting with Django , any suggestions on what would be a good starting point/resource to learn Django from ?

I am a beginner with some basic experience in python but no exposure to any other language what so ever.

/r/django
https://redd.it/yszn3t

Читать полностью…

Python Daily

HOW TO ACCESS VARIABLE OUTSIDE LOOP

I have a loop in jinja which displays a collection of items. I included a purchase button in each item whereby clicking it brings up a modal popup where i plan to set up a form to collect some data before posting it to the backend. I'm stuck in trying to get the id of each item since the modal is outside the loop.

I tried using js which i could only be able to display the id in modal using innerHTML. How can I access the id value in jinja?

/r/flask
https://redd.it/ysxlpo

Читать полностью…

Python Daily

Saturday Daily Thread: Resource Request and Sharing! Daily Thread

Found a neat resource related to Python over the past week? Looking for a resource to explain a certain topic?

Use this thread to chat about and share Python resources!

/r/Python
https://redd.it/ysr8ns

Читать полностью…

Python Daily

Something cool I learned about Python: a Windows MessageBox can be displayed to the user from a running script, without any dependency on a UI library or framework
https://mfcallahan.blog/2022/11/10/display-a-message-box-with-python-without-using-a-library-or-other-dependency-windows/

/r/Python
https://redd.it/ysfo1x

Читать полностью…

Python Daily

Remove extra square brackets from json response



Hello guys, I am working on a weather app and this is my first time building a project using Flask and calling APIs. I am trying to get the weather description but it returns like this:

'Partly Cloudy'

How do I remove the square brackets and quotation sign?

/r/flask
https://redd.it/ys2rxm

Читать полностью…

Python Daily

How should I treat my python installation?

This is like the third time I've formatted my computer this month, and I just now remembered my Python installation being all messed up was one of the reasons I decided to do that!

What is the best way to go about managing python packages/environments? Conda, miniconda, poetry, pip? Specifically, what should I use and how should I use it to keep my environments and installation clean?

/r/Python
https://redd.it/ys4dhe

Читать полностью…

Python Daily

Django Theme BS5 - Argon / MIT / Usable via PyPi / Theme can be used for common users also
https://github.com/app-generator/django-admin-argon-dashboard

/r/django
https://redd.it/yro425

Читать полностью…

Python Daily

What Are the Most Common Mistakes That People Are Doing in Learning Python? 5,000+ Learners' Data Analyzed

As some of you may know, my friends and I launched an app called Codehub a month ago, and it already has 5,000+ users. The app offers free Python challenges to practice. We've analyzed the data of all 5,000 users to understand the most common mistakes people make while doing the Python challenges.

Common Error #1: Syntax Errors

Over 2,400 people had syntax errors. These mistakes include omitting a keyword, misspelling variable names, and omitting a symbol such as a colon, comma, or bracket.

Common Error #2: Logical Errors

These errors occur when a program does not crash but produces an incorrect result. Over 14,000 challenges were completed on Codehub in the previous 1.5 months, and 40% had logical errors. These include using integer division instead of floating point division and using wrong variable names.

Common Error #3: Iterating over a list and modifying it

Deleting an item from a list or array while iterating over it is a widespread error, not just in our app's context. While some of these issues may be obvious to the naked eye, others may be difficult to identify and resolve.

If this is interesting, please let me know. I plan to publish an extended article about the most common

/r/Python
https://redd.it/yrnp2k

Читать полностью…

Python Daily

I'm working with a small team in a Django project, one of the requirements says that I need to use MSSQL SERVER, but I don't know how to share the database

Hi, I'm working on a university Django project, one of the requirements was to use MSSQL SERVER, but I'm having problems sharing the database.

I was thinking that a solution would be to use SQLite and then migrate back to MSSQL SERVER, but I read that it creates different problems when more than three people work on the same embedded database.

A friend suggested me another solution which is to work on Digital Ocean and use free credit, but I don't know how to work on a host, what should be the methodology with GitHub?

If anyone has a better idea or thinks any of this could work, it would be a great help.

/r/django
https://redd.it/yrnilt

Читать полностью…
Subscribe to a channel