I've heard that "if a class is just a constructor and one method, then it should be a function". What is your opinion on this and what are counter examples?

I watched a seminar a few years ago about someone talking about the misuses of OOP in python and talked extensively about the case where people write a class, implement the `__init__()` method and one extra method and that's it.

He provided examples and showed functional code that simplifies the solution to a few lines and he said:

> "If a class is just a constructor and one method, then it shouldn't be a class at all. It should be a function."

I can't find the video anymore, but I was just wondering what reddit thinks about this statement and if you have any counter examples or in what cases it could be useful.

I'm also interested in the cases where if it is true, how would that functional implementation look like when I need some sort of a state to persist.

EDIT: Awesome discussion in the comments. Thanks for everyone's input!


Resume Generation With Python


Latest Python for Debian GNU/Linux


what's sentiment analysis methodology

* Discuss sentimental analysis.
* Describe the Python download and installation process.
* Define polarity and subjectivity.
* Explain the use of textBlobs.
* Contrast lemmatization to tokenization
* Discuss the POS Tag language.
* Explain Bigrams, Trigrams and Ngrams.
* List the various Anaconda applications.
* Summarize capitalizations, pluralizations and singularizations.
* Outline loops in Ngrams.
* Describe TextBlob classification.
* Relate data frame to the classification of sentiments.

[https://alison.com/topic/learn/129326/sentimental-analysis-methodology-learning-outcomes](https://alison.com/topic/learn/129326/sentimental-analysis-methodology-learning-outcomes)


Python Cybersecurity — Build your own python tools (PortScanner, Visual Network Tracker and Anonymous FTP Scanner)

**Python Cybersecurity — PortScanner**

Build a simple Port Scanner using the Python Programming language. Port Scanner is an application designed to probe a server or host for open ports. Such an application may be used by administrators to verify security policies of their networks and by attackers to identify network services running on a host and exploit vulnerabilities.

**YouTube Link**: [https://youtu.be/bH-3PuQC\_n0](https://youtu.be/bH-3PuQC_n0)

**Medium Link:** [https://medium.com/vinsloev-academy/python-cybersecurity-build-a-port-scanner-13b798a1b654](https://medium.com/vinsloev-academy/python-cybersecurity-build-a-port-scanner-13b798a1b654)

**Python Cybersecurity — Visual Network Tracker**

Dive into Network Traffic visualization using the Python programming language, Wireshark and Google Maps. This tutorial covers the implementation steps needed to take a file of network traffic and convert it into a visual presentation using Google Maps.

**YouTube Link**: [https://youtu.be/xuNuy8n8u-Y](https://youtu.be/xuNuy8n8u-Y)

**Medium Link:** [https://medium.com/vinsloev-academy/python-cybersecurity-network-tracking-using-wireshark-and-google-maps-2adf3e497a93](https://medium.com/vinsloev-academy/python-cybersecurity-network-tracking-using-wireshark-and-google-maps-2adf3e497a93)

**Python Cybersecurity — Anonymous FTP Scanner**

Build a simple FTP Scanner using the Python Programming language. Anonymous FTP is a means by which archive sites allow general access to their archives of information. These sites create a special account called “anonymous”

**YouTube Link**: [https://youtu.be/BIZfRodSW9w](https://youtu.be/BIZfRodSW9w)

**Medium Link:** [https://medium.com/vinsloev-academy/python-cybersecurity-for-beginners-build-anonymous-ftp-scanner-a62f0534fcf5](https://medium.com/vinsloev-academy/python-cybersecurity-for-beginners-build-anonymous-ftp-scanner-a62f0534fcf5)


Business logic in Django and Django REST Framework applications


Python finally offloads some batteries


Proposed Addition to Python ASYNC.

I'm a big fan of using Python for distributed computing. I have used the Twisted framework for years and the process level support. I love that we now have Future, Async, and Await as a standard part of the language.

I've been thinking that the next step has to be merging together the threading and process level into a single langauge. This got me thinking with little change why not support the following language syntax/semantics:

&#x200B;

typeOfEnttity := 'process' | 'thread';

func := \[async \[typeOfEntity\]\] def ....

&#x200B;

The idea is that if I say

def foo() ... it is the Python standard.

&#x200B;

If I say

async def foo()  or async thread def foo()  ...

 we have the asyncio stuff we have today.

&#x200B;

If  I say

async process def foo() ....

I have it using the multiprocess support of Python. I think this movies python in the "right" direction. I'm wondering what you all think about this proposal?


Python ETL management framework/tool

Hello,

I am trying to build some ETL scripts; mainly getting data from different sources and loading to my database. Python libraries are great for this and it works perfectly.

My question is related to the way these scripts etc. might be automated, managed.

Is there any framework, tool you could suggest? How do people manage this stuff?

Sorry, I am new to this and I am not sure if my quesiton is clear.


Finance degree to cs?

So I studied finance  and have a little bit of work experience in marketing, which are not related to cs at all.

I've been through a lot ups and downs (mainly just downs, really) and I've set my mind to change my life for the better. I'm not going to elaborate on whatever happened as it is off the topic.

I am just wondering how hard it is for smn with no experience to learn CS? I know many agencies are selling classes, and opinions from my friends are divided. Some said it is my best chance to get the life I want, which I agree; some said that it is too hard and it's not worth the effort as I'll have to go back and do a bachelor degree.

Any advice?


Share Jupyter Notebook as web app


Building an all-in-one Python Resources Website for Python Developers

Hey there,

I am building a Python Resources Website. Divided into two main Pages (Web Backend and AI/Machine Learning) for these Resources, the goal is to simplify the search for some of the best React resources such as:

**1) For Python/Backend:**

• Django, Flask, FastAPI Articles

• Django, Flask, FastAPI Forums latest Discussions (Reddit)

• Django, Flask, FastAPI YouTube Channels Videos

• Django, Flask, FastAPI Websites

• Django, Flask, FastAPI E-books, Snippets

• *Job Opportunities*

&#x200B;

**2) For Python/AI/ML:**

• AI/ML Articles

• AI/ML Forums latest Discussions (Reddit)

• AI/ML YouTube Channels Videos

• AI/ML Websites

• AI/ML E-books, Snippets

• *Job Opportunities*

&#x200B;

I've done a  [Similar App](https://helloreact-beta.vercel.app/) for React Developers, and I'm now building the Python version.

Can you give me some of the best resources out there (blogs, Youtube Channels, Websites, Forums)? I'd like to feature the in the Project.

&#x200B;

Thank You :)


Frontend Vue and Tailwind Setup - Masonite Tutorial


A solver, player and cheater for breaklock

I stumbled upon [breaklock](https://www.mathsisfun.com/games/breaklock.html) recently. Since it was a bit too much for me, I set up a program to solve it.

The solving mode works by first finding all possible solutions, then whittling down the options based on feedback from the game, I can explain further if required.

The player mode simply asks the player to make moves until they win.

I love the cheating mode idea, which just popped into my head. Essentially, when the player gets the correct answer, it changes it while ensuring no contradictions happen. Like you do in hangman. On average, it slows down the machine by \~1 turn, and humans by \~5 turns

&#x200B;

Visit it on github [here](https://github.com/deltaqyto/breaklock-solver)


Is this a good project?

So I'm making classes out of multiple libraries such as tweepy (Twitter scraping) to make them very user friendly.

I'm adding methods such as "gather_maximum_tweets()" that will work for 2 hours and give you at least 100k tweets instead of the 18k that you'll get from tweepy every 15 minutes of sleep (In other words, made it automatic).

Some methods to clean the text and visualize it.

Is it a good project? Can I make an API out of it? Should I make it open source and put it on github? Is making a video explaining my project will be good for my open source code? Or should I try to sell it?

(Considering it is my first project)


8 Excellent Python Courses on Udemy (2022)


Python Traffic Generator


Friday Daily Thread: Free chat Friday! Daily Thread

Use this thread to talk about anything Python related! Questions, news,  projects and any relevant discussion around Python is permitted!


How would you compare tortoise ORM vs peewee ORM?

Since they are both similar to the Django ORM, then they can be clasified as active record ORMs right?

Have you used any or both? If so how was your experience and which would you recommend?


#FOSS Fintech In Python: Using GameStonk Terminal To Generate Trade Ideas


Arcade 2.6.11 has been released

Python Arcade, a library for creating 2D arcade games, has released version 2.6.11.

Website: [https://arcade.academy](https://arcade.academy)

Release notes: [https://api.arcade.academy/en/latest/development/release\_notes.html](https://api.arcade.academy/en/latest/development/release_notes.html)

Demo video: [https://www.youtube.com/watch?v=QClDvEwcxmg](https://www.youtube.com/watch?v=QClDvEwcxmg)

&#x200B;

**Release notes**

* Sections - Add support to divide window into sections. (Thanks [janscas](https://github.com/janscas) for the contribution.)
   * Add [arcade.Section](https://api.arcade.academy/en/latest/api/window.html#arcade.Section) to the API.
   * Add [arcade.SectionManager](https://api.arcade.academy/en/latest/api/window.html#arcade.SectionManager) to the API.
   * Add examples on how to use: [Dividing a View Into Sections](https://api.arcade.academy/en/latest/examples/index.html#section-examples)
* New Example Code:
   * Add parallax example: [Parallax](https://api.arcade.academy/en/latest/examples/parallax.html#parallax).
   * Add GUI flat button styling example: [Flat Text Button Styled](https://api.arcade.academy/en/latest/examples/gui_flat_button_styled.html#gui-flat-button-styled).
   * Add [Perspective](https://api.arcade.academy/en/latest/examples/perspective.html#perspective) example.
* New functionality:
   * Add [arcade.get\_angle\_degrees()](https://api.arcade.academy/en/latest/api/geometry.html#arcade.get_angle_degrees) function.
   * Add easing functions and example. See [Easing Example 1](https://api.arcade.academy/en/latest/examples/easing_example_1.html#easing-example-1) and [Easing Example 2](https://api.arcade.academy/en/latest/examples/easing_example_2.html#easing-example-2).
   * Add arcade.Sprite.facePoint()
 to face sprite towards a point.
* Fixes:
   * Fixed issue [\#1074](https://github.com/pythonarcade/arcade/issues/1074) to prevent a crash when opening a window.
   * Fixed issue [\#978](https://github.com/pythonarcade/arcade/issues/978), copy button in examples moved to the left to prevent it disappearing.
   * Fixed issue [\#967](https://github.com/pythonarcade/arcade/issues/967), CRT example now pulls from resources so people don’t have to download image to try it out.
   * PyMunk sample map now in resources so people don’t have to download it.
   * [arcade.draw\_points()](https://api.arcade.academy/en/latest/api/drawing_primitives.html#arcade.draw_points) no longer draws the points twice, improving performance.
* Documentation:
   * Update [Pygame Comparison](https://api.arcade.academy/en/latest/pygame_comparison.html#pygame-comparison).
   * Improve Sprite.texture
 docs.
   * When building Arcade docs, script now lets us know what classes don’t have docstrings.
   * Spelling/typo fixes in docs.
* Misc:
   * Update arcade.Sprite
 to use decorators to declare properties instead of the older method.
   * [\#1095](https://github.com/pythonarcade/arcade/issues/1095), Improvements to [arcade.Text](https://api.arcade.academy/en/latest/api/text_pyglet.html#arcade.Text) and its documentation. We can now also get the pixel size of a Text contents though content\_width, content\_height and content\_size.
   * Force GDI text on windows until direct write is more mature.
   * Optimized text rendering and text rotation
   * [arcade.draw\_text()](https://api.arcade.academy/en/latest/api/text_pyglet.html#arcade.draw_text) and [arcade.Text](https://api.arcade.academy/en/latest/api/text_pyglet.html#arcade.Text) objects now accepts any python object as text and converts it into a string internally if needed.
   * [SpriteList](https://api.arcade.academy/en/latest/api/sprite_list.html#arcade.SpriteList) now exposes several new members that used to be private. These are lower level members related to the underlying geometry of the spritelist and can be used by custom shaders to do interesting things blazingly fast. SpriteList interaction example with shaders can be found in the experimental directory. Members include [write\_sprite\_buffers\_to\_gpu()](https://api.arcade.academy/en/latest/api/sprite_list.html#arcade.SpriteList.write_sprite_buffers_to_gpu), [geometry](https://api.arcade.academy/en/latest/api/sprite_list.html#arcade.SpriteList.geometry), [buffer\_positions](https://api.arcade.academy/en/latest/api/sprite_list.html#arcade.SpriteList.buffer_positions), [buffer\_sizes](https://api.arcade.academy/en/latest/api/sprite_list.html#arcade.SpriteList.buffer_sizes), [buffer\_textures](https://api.arcade.academy/en/latest/api/sprite_list.html#arcade.SpriteList.buffer_textures), [buffer\_colors](https://api.arcade.academy/en/latest/api/sprite_list.html#arcade.SpriteList.buffer_colors), [buffer\_angles](https://api.arcade.academy/en/latest/api/sprite_list.html#arcade.SpriteList.buffer_angles) and [buffer\_indices](https://api.arcade.academy/en/latest/api/sprite_list.html#arcade.SpriteList.buffer_indices)
* OpenGL:
   * Added support for indirect rendering. This is an OpenGL 4.3 feature. It makes us able to render multiple meshes in the the same draw call providing significant speed increases in some use cases. See [arcade.gl.Geometry.render\_indirect()](https://api.arcade.academy/en/latest/gl/geometry.html#arcade.gl.Geometry.render_indirect) and examples in the experimental directory.
   * Added support for unsigned integer uniform types
   * arcade.gl.Geometry.transform
 no longer takes a mode parameter.

Special thanks to [einarf](https://github.com/einarf), [eruvanos](https://github.com/eruvanos), [janscas](https://github.com/janscas), [MrWardKKHS](https://github.com/MrWardKKHS), [DragonMoffon](https://github.com/DragonMoffon), [pvcraven](https://github.com/pvcraven), for their contributions to this release. Also, thanks to everyone on the Pyglet team! We depend heavily on Pyglet’s continued development.


I'm an amateur Python programmer, what's my next step?

I've been coding in Python for years now & I've done a wide range of projects from discord bots to analysing CO2 data but now I'm at a loose end.

Ideally either I'd help open source projects or I'd help specific people, the problem is I've never done open source stuff before & all the active projects I can find are big, complex projects which are daunting by themselves.

Does anyone know any smaller open source projects that need/want help or specifically where to find them or where I can work with a small group of people on a project?


Bookmarking Application (sqlite, tkinter, bcrypt)

My largest project so far, pretty happy with what I learned about passwords/account creation, and what felt like a decent intro to databases.

&#x200B;

This program will let you make an account, save bookmarks to a database, and then reference only the bookmarks saved to the logged in account, along with a few other features listed in the github readme.

&#x200B;

Goal of this program was to get some idea of how to use a database, figure out how to create a user account system, and to work on my code readability and structure.

&#x200B;

Please hit me with some feedback! Questions or criticism on anything would be much appreciated.

&#x200B;

&#x200B;

[landing page after login, with access to the other pages of the program.](https://preview.redd.it/d6gbs4qq1zn81.png?width=428&format=png&auto=webp&s=79c59bccb5171aee8742d13e7edb0e183df17ff4)

&#x200B;

the project: [https://github.com/ZG34/Bookmarkus](https://github.com/ZG34/Bookmarkus)


Package for printing text with RGB colors in the console

As a quick introduction:

I'm making my own writing software to write my science fiction story with. As I started out knowing nothing about the language back in August, I made the foolish decision to use as little third party libraries as possible (where sensible). This made me learn quite a lot about the language and how certain things work in the world of programming.

Last week I decided to replace my dependency on Colorama with my own package: **AthenaColor**

The library supports the same structure as Colorama (Fore, Back, Style), but with a much expanded color base. Namely I have chosen to predefine all expanded html colors in the Fore and Back colors.

All ANSI Select Graphic Rendition parameters are also implemented, yet most of them do not work in PyCharm. I've decided to put the ones that don't work in the PyCharm console under Style.Unverfified.

I'm also working on the capabilities to put in blinking text, and other similar methods, but these aren't within the project yet. When they are, I will update this post.

[A limited view of all predefined colors and all the Stylings you can do](https://preview.redd.it/s2is7qs2zyn81.png?width=1007&format=png&auto=webp&s=c36ca104e1a04d41bd89d339d9932b32b2c68301)

&#x200B;

[All predefined colors](https://preview.redd.it/0l2f2moe0zn81.png?width=367&format=png&auto=webp&s=0d118d58c979b3c6065ce3a310964c55a75498bd)

The library also allows you to define custom RGB objects to use within the library, allowing you to print all 16.777.216 possible colors.(I've tried to make a print out in PyCharm of all these colors for fun, to see what would happen, and PyCharm doesn't like it when you try to do this)

&#x200B;

Source code: [https://github.com/DirectiveAthena/VSC-AthenaColor](https://github.com/DirectiveAthena/VSC-AthenaColor)
PyPi link: [https://pypi.org/project/AthenaColor/](https://pypi.org/project/AthenaColor/)

&#x200B;

Small addendum: I'm a hobbyist Developer who only uses PyCharm as my development environment, so if there are any issues with another program, I will happily try to solve them, but cannot promise that these issues will be fixed as soon as possible


Is programming easy or am I doing things wrong?

I started learning python around 5 months ago, with some breaks and inconsistency but for the last 2 months I have been steadily learning it, 4-10 hours daily. I am in a position where I am being mentored for a business sector that is really technology-based, so I am familiar with 'professional' programming costs and time frames.

One time, the owner talked about hiring a company to make a program/web app, so I took it as an opportunity to attempt to do the project myself, just as a learning opportunity.

The quote was like tens of thousands of $$$, and they say it will take multiple months to do (not because they're booked up).

And this is something simple like following docs of another service to integrate with a very simple front-end and a decent SQL database. I just feel like I must be doing something wrong if it only takes me, a single person, a month and a half to have a complete product that works.

I just don't understand how I can do it so quickly, but professional programmers take way longer and charge so much. Is there a reason? Such as multiple layers of protection from hiccups and bugs, etc.?Could it also be that I understand the software and they would need to delve into it more? Am I some genius programmer? /s but seriously, very curious and confused. (And I understand this can be a question that seems like a brag or something)

The owner even brought up when I showed him the software that it must be programmed wrongly if it could be done so quickly.


A template engine I did...

I have been looking for project inspirations, I ended up creating this template engine https://github.com/mauro-balades/yate


Frelatage: A fuzzing library to find vulnerabilities and bugs in Python applications

&#x200B;

Frelatage is a coverage-based Python fuzzing library which can be used to fuzz python code. The development of Frelatage was inspired by various other fuzzers, including [AFL](https://github.com/google/AFL)/[AFL++](https://github.com/AFLplusplus/AFLplusplus), [Atheris](https://github.com/google/atheris) and [PyFuzzer](https://github.com/eerimoq/pyfuzzer).The main purpose of the project is to take advantage of the best features of these fuzzers and gather them together into a new tool in order to efficiently fuzz python applications.

Github repo: [https://github.com/Rog3rSm1th/Frelatage](https://github.com/Rog3rSm1th/Frelatage)

PyPi: [https://pypi.org/project/frelatage/](https://pypi.org/project/frelatage/)

Demo:

https://i.redd.it/anvsvnedmyn81.gif


Announcing compushady: a Python module for easily running Compute Shaders


Roles and Permissions in Masonite


Online Python environment for middle school students (Chromebooks)

Hello,

we're looking for an online environment to let students (age 11-13) play with Python. We need an online resource to avoid installing anything on Chromebooks.

Ideally this would work with Google Drive to save projects.

For now I've found this simple tool: [https://www.online-python.com/](https://www.online-python.com/)

Is there anything better you would suggest?

Thanks!


High-level tools to simplify visualization in Python


5 Steps to Master Python Decorator


End to end encrypted pastebin built with Starlette (as the file server.)

Recently when looking to deploy a simple pastebin onto my self hosted server I found it difficult to find any modern docker deploy-able pastebins what were secure by default. This inspired me to create my own.

Paaster is a secure by default end to end encrypted pastebin built with Svelte, Vite, Typescript, Python, Starlette, rclone  & Docker.

[Github](https://github.com/WardPearce/paaster) (Any stars or merges appreciated)

[paaster.io](https://paaster.io)

[Example paste](https://paaster.io/NqU-4gSo2SSWXhIBSct9l#hD8y8CEr4JjRpuo2nrdL6xGtBIP17QPbpGv2Ld1jlMA)

# Preview

[Preview](https://i.redd.it/oskt8a6upun81.gif)

# Features

* End to end encryption.
* Rate limiter (with redis).
* Shortcuts.
* Rclone supported.
* Nano IDs.
* Paste history.
* Auto code highlighting.
* Memory efficient file handling .
* Server secrets bcrypt hashing.

# Future plans

* Unit tests
* File uploading


_ctypes in pure python code:

I've found the needed components to potentially put \_ctypes.c code into python scripts. I've also found the needed preprocessor to make such work.


Thursday Daily Thread: Python Careers, Courses, and Furthering Education!

Discussion of using Python in a professional environment, getting jobs in Python as well as ask questions about courses to further your python education!

**This thread is not for recruitment, please see** r/PythonJobs **or the thread in the sidebar for that.**


Python 3.10.3, 3.9.11, 3.8.13, and 3.7.13 are now available with security content


Network Tracking using Wireshark and Google Maps - Python3


First time to work in python

hello guys i’m new here and I have question about python. what exactly you guys doin at work ? i’m bout to apply for a job and I have no idea what to do or what they’re expecting me to do.


First steps into async Python


Composer: a new PyTorch library to train models ~2-4x faster with better algorithms

Hey all!

We're excited to release Composer ([https://github.com/mosaicml/composer](https://github.com/mosaicml/composer)), an open-source library to speed up training of deep learning models!

https://preview.redd.it/87if2pufdsn81.png?width=3009&format=png&auto=webp&s=0238e6bf3050be3e4db27ca07dbbea80a16a7f49

Composer lets you train:

* A ResNet-101 to 78.1% accuracy on ImageNet in 1 hour and 30 minutes ($49 on AWS), **3.5x faster and 71% cheaper than the baseline.**
* A ResNet-50 to 76.51% accuracy on ImageNet in 1 hour and 14 minutes ($40 on AWS), **2.9x faster and 65% cheaper than the baseline.**
* A GPT-2 to a perplexity of 24.11 on OpenWebText in 4 hours and 27 minutes ($145 on AWS), **1.7x faster and 43% cheaper than the baseline.**

https://preview.redd.it/hf8u1mk1esn81.png?width=10008&format=png&auto=webp&s=a5606571bf6a23c607d58648e654bdd2184afd83

Composer features a **functional interface** (similar to torch.nn.functional), which you can integrate into your own training loop, and a **trainer,** which handles seamless integration of efficient training algorithms into the training loop for you.

**Industry practitioners:** leverage our 20+ vetted and well-engineered implementations of speed-up algorithms to easily reduce time and costs to train models. Composer's built-in trainer makes it easy to **add multiple efficient training algorithms in a single line of code.** Trying out new methods or combinations of methods is as easy as changing a single list, and [we provide training recipes](https://github.com/mosaicml/composer#resnet-101) that yield the best training efficiency for popular benchmarks such as ResNets and GPTs.

**ML scientists:** use our two-way callback system in the Trainer **to easily prototype algorithms for wall-clock training efficiency.**[ Composer features tuned baselines to use in your research](https://github.com/mosaicml/composer/tree/dev/composer/yamls), and the software infrastructure to help study the impacts of an algorithm on training dynamics. Many of us wish we had this for our previous research projects!

**Feel free check out our GitHub repo:** [https://github.com/mosaicml/composer](https://github.com/mosaicml/composer), and star it ⭐ to keep up with the latest updates!


Tool detection using phone and Machine Learning

&#x200B;

https://reddit.com/link/tfny9g/video/nvbynxiyasn81/player

Making my phone as an Extension of the camera I can detect objects in my laptop by streaming feed into OpenCV sing YOLO

[source](https://github.com/Aaris-Kazi/Tool-Detection-using-YOLO/)


I fixed python traceback real quick

&#x200B;

https://preview.redd.it/yqvg54ml9sn81.png?width=2000&format=png&auto=webp&s=575484421b18464c240d3f384d3a1c7e3f4e3a34

    yourprog = "whatever.py"

    from subprocess import check_output, STDOUT

    def abrT(r):
      return r
      o = ""
      # I don't care about unreadable code I am writing this during lunch break
      for line in r.split("\n"):
        if "Traceback" in line:
          o += "Traceback:\n\n"
        elif "File" in line:
          a = line[line.find(", ")+2:] + "\n"
          a = a.replace(", in <module>", "")
          o += "  " + a
        elif ":" in line:
          o += "\n  " + line.split(": ")[0] + ":\n    " + line.split(": ")[1] + "\n"
        else:
          o += line + "\n"
      return o[:-1]

    result = str(check_output(f"python3 {yourprog}; echo -n", shell=1, stderr=STDOUT), 'utf-8')
    print(abrT(result))


Scrape Google Books in Python

This blog post uses [`parsel`](https://parsel.readthedocs.io/) as an HTML/XML parser that supports full XPath, instead of [`bs4`](https://www.crummy.com/software/BeautifulSoup/bs4/doc/).

Shows how to scrape:
- title
- link
- displayed link
- snippet
- author
- publication date
- thumbnail
- preview, and more editions.

If you need a step-by-step explanation, you can visit [Scrape Google Books in Python](https://serpapi.com/blog/scrape-google-books-in-python/) blog post at SerpApi, otherwise:

```python
from parsel import Selector
import requests, json, re

params = {
    "q": "richard branson",
    "tbm": "bks",
    "gl": "us",
    "hl": "en"
}

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.87 Safari/537.36",
}

html = requests.get("https://www.google.com/search", params=params, headers=headers, timeout=30)
selector = Selector(text=html.text)

books_results = []

# https://regex101.com/r/mapBs4/1
book_thumbnails = re.findall(r"s=\\'data:image/jpg;base64,(.*?)\\'", str(selector.css("script").getall()), re.DOTALL)

for book_thumbnail, book_result in zip(book_thumbnails, selector.css(".Yr5TG")):
    title = book_result.css(".DKV0Md::text").get()
    link = book_result.css(".bHexk a::attr(href)").get()
    displayed_link = book_result.css(".tjvcx::text").get()
    snippet = book_result.css(".cmlJmd span::text").get()
    author = book_result.css(".fl span::text").get()
    author_link = f'https://www.google.com/search{book_result.css(".N96wpd .fl::attr(href)").get()}'
    date_published = book_result.css(".fl+ span::text").get()
    preview_link = book_result.css(".R1n8Q a.yKioRe:nth-child(1)::attr(href)").get()
    more_editions_link = book_result.css(".R1n8Q a.yKioRe:nth-child(2)::attr(href)").get()

    books_results.append({
        "title": title,
        "link": link,
        "displayed_link": displayed_link,
        "snippet": snippet,
        "author": author,
        "author_link": author_link,
        "date_published": date_published,
        "preview_link": preview_link,
        "more_editions_link": f"https://www.google.com{more_editions_link}" if more_editions_link is not None else None,
        "thumbnail": bytes(bytes(book_thumbnail, "ascii").decode("unicode-escape"), "ascii").decode("unicode-escape")
    })
```


OpenTelemetry and Distributed Tracing in Python - Introduction


Add jemalloc to your Python Docker images


What's your favorite module/library/package?

Just wondering what's your favorite module and package which you like to use them? Mine is re.

You can tell multiple, by the way.


Writing production grade pandas with hamilton!

While Pandas is incredibly flexible and easy to get started with, it doesn't lend itself to writing good quality, extensible code. This is usually fine. Lots of it is thrown away -- written in notebooks and never seen again. However, a  lot amount of it ends up making it into production ETLs, services, etc..

At Stitch Fix, we had a *lot* of monolithic, messy pandas scripts. We built [hamilton](https://github.com/stitchfix/hamilton/) to solve this problem. A programmer represents transforms on dataframes as a series of python functions. The parameter names are used to specify upstream dependencies, and the whole thing gets wired into a dependency graph.

In short -- instead of writing:

    df['a'] = df['b'] + df['c']

You'd write:

    def a(b: pd.Series, c: pd.Series) -> pd.Series:
        return b+c

Then you use a *driver* to customize execution, pass in paraemeters, etc... Note that its not at all limited to pandas -- while that was the initial use-case, it can handle any sort of python datatype!

We've opened up this internal tool we're excited about to the outside world -- we'd love feedback, contribution, and use-cases!

[https://github.com/stitchfix/hamilton/](https://github.com/stitchfix/hamilton/)


First time I used python

I'm coding with python for half a month now, in the beginning I was a bit sceptical what I would use it for but today I used it for the first time.

To cure boredom, me and my friends are doing typeraces where we have to type as fast as possible. I'm pretty good at that but there is someone in my class that is just a little better. Its just because I type upper cases with shiftlock and she types with shift.

So I wanted to learn to type with shift so I could type faster. But because I never did it that way I had to practice it so I wrote a little python program that generates a letter and then you have to type that letter.

I was very happy how it turned out and I now I understand python can and will be very useful .


OPToggles - a feature flag Open Source project

Hey r/Python! Just wanted to share our open source project launching today. Thought some of you might find it useful, and we would love to hear your feedback.

As devs, we often want our frontend to reflect the permissions enforced by the backend - i.e. if a user is not allowed to run the action behind a button - don't show the button.

[OPToggles](https://github.com/permitio/OPToggles) uses[ Open Policy Agent](https://github.com/open-policy-agent/opa) to automatically enhance feature flag solutions by creating user-targeted feature flags. It already supports LaunchDarkly and a generic REST API.


How do you really share constants across your project in a Pythonic way?

Assuming i have a package i created who get input text, and return a huge dictionary with 50+ keys.

Since *all other packages* in the program are using this dictionary and play with those keys,  I don't want to hard code the keys, but keep them as global **constants**.

So here are my options and i feel uncomfortable with both of them:

1. Put all constants vars in a separate folder/package in root folder, and *import them to each package* that use them. To my eyes it makes the code **hairy and uncapsulated.** I love the SW engineering where you have a package that depend on nothing outside.
2. Pass all arguments in this config package to *each* package who need it - which also make things ugly hairy and confusing, and require putting all constants in a class(there are no structures.)

&#x200B;

I know that most people go with **1**, but my code has like 10+ packages i wrote, each package has multiple files, ***each*** depend on these constants(50+), and if i import the constants (even with **absolute import**) to each, it makes me feel uncomfortable.

What if i want to give my package to another developer ? i need to gather all these dependencies?

**How is this done in huge multi developers programs ?**


Import of modules is slowing down executable. Can it be imported locally or what can be done differently ?

I am importing the following modules/libraries which is causing the exe to take a few minutes to start. How can I store them locally or what can I do differently so that the exe starts quickly? When I run this from the Notebook it the application runs without any delay. I wonder if there is a way to speed up the exe.

import time
import openpyxl
from os import path
from selenium import webdriver
from openpyxl.styles import Alignment
from webdriver\_manager.chrome import ChromeDriverManager
from openpyxl.styles.borders import Border, Side
from selenium.webdriver.support.ui import Select
import os
import math
import win32com.client as client
from PIL import ImageGrab

&#x200B;

Thank you in advance.


Stylistic choice of validation functions

Hey all! Got a question. I’m working on a validation script for work verifying some supplied input against required values. I’m wondering, stylistically, if there’s a “preferred way” to write these functions.

An example function…

    Def name_max_length(name):
        if 1 < len(name) <= 128:
             return None
        else:
             raise     ValidationError(“Names length fell outside of max range.”)

Apologies if Reddit mobile mangled that code but it’s short enough that I think everyone can still grok it.

If you were working on a project would you want to see the above? Or would you rather read a single if statement, without an else, checking to see if it fell outside of the valid range and if so raise the exception.

I thought PEP-8 had a stylistic recommendation about positive vs negative checking for if statements but I gave it a quick scan and didn’t see anything. I’m going to be writing a lot of these, so I’d like to get a solid stylistic choice under me.

I’m also curious, would you rather see these ranges hard coded in the if statement, or see two local variables (min/max) and have “if”compare against those?


what to do after practice python. org?

Helo I'm a beginner and I've finished the exercises from practice python org and I m clueless as to what my next step should be. What do you recommend, I tried advent of code but a lot of the exercises are way too hard for me. thanks very much


Create a hello world app using django


My first ever Python Project!! I named it tagSearch

I saw a twitter post the other day "Is there a tool that I can get meta tags off of a web site? I couldn't find any".

I thought to myself, there probably is, but I should do one too for at least practice.

So I made this small script called tagsearch, basically it collects wanted tags off a site. It can also scrape certain tags that have a wanted attribute, like span tags but only if they have class attr.

I also added regex support meaning one can make regex search on the scraped tags. My GitHub repo:

[https://github.com/teooman/tagsearch](https://github.com/teooman/tagsearch)

Example image

https://preview.redd.it/5ic7krt7aqn81.png?width=1419&format=png&auto=webp&s=afabf3817e73dc2075bbf2be6017c2bc76d36298

Any feedback would be highly appreciated!!


created a small utility to automatically activate Poetry virtualenvs when changing directories

[https://github.com/tvaintrob/auto-poetry-env](https://github.com/tvaintrob/auto-poetry-env)

tested only on MacOS with zsh, heavily inspired by pyenv-venv's auto activation, please share any thoughts and suggestions!


GitHub - jamalex/notion-py: Unofficial Python API client for Notion.so


Which logic for if-else inside a function is better or more pythonic?

The logic between f1 and f2 is exactly the same, but the syntax is slightly different. This type of function shows up everywhere. Is one easier to read, or preferred in some way?

Side note: I thought it was interesting that f2 is slightly faster than f1.

    import numpy as np

    arr = np.random.choice(['a','b','c'],100)

    def f1(cond):
        if cond == 'a':
            return 'a'
        if cond == 'b':
            return 'b'
        return 'c'

    def f2(cond):
        if cond == 'a':
            return 'a'
        elif cond == 'b':
            return 'b'
        else:
            return 'c'

f1 timeit:

    In [1]: %%timeit
        ...: for i in arr:
        ...:     f1(i)
        ...:
    40.6 µs ± 804 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

f2 timeit:

    In [2]: %%timeit
        ...: for i in arr:
        ...:     f2(i)
        ...:
    40.2 µs ± 729 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

edit: u/hai_wim pointed out that the speeds are fully equal (difference is within stdev tolerance), as the byte code is exactly the same. So the question really comes down to readability and standardization.


Approach H2kinfosys to Learn Python Course Effectively

This [**python certification online**](https://www.h2kinfosys.com/courses/python-online-training) course  is created for complete beginners, so you don't need any prior programming experience to complete it. The outline is designed to cover the basics of the programming language as well as some advanced topics.


macOS 12.3 finally deletes its own Python 2, which even die-hard Python fans applaud


Tool to get path to JSON in python format

I found a tool that you can paste JSON into, provide the key to look for, and the value expected for the key (partial values works too). The result is the path to the value.

Wanted to share as I found this useful.

https://xenosoftwaresolutions.com/json

sample JSON:

    {
        "test": [
            {
                "item": true,
                "checked": false,
                "info": {
                    "hello": "world"
                },
                "products": []
            }
        ]
    }

result when looking for hello as key and world as value:

    ["test"][0]["info"]["hello"]


Wednesday Daily Thread: Beginner questions

New to Python and have questions? Use this thread to ask anything about Python, there are no bad questions!

This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at [https://discord.gg/python](https://discord.gg/python) where you stand a better chance of receiving a response.


Approximate Pi with 7 lines of code (arctangent series)


Article: Build a webhook in Python to interact with GitLab.


Which is more Pythonic?

    if event_region in match regions:
        return True
    else:
        return False`
Or...

`Return True if event_region in match_regions else False`

Or...

`return event_region in match_regions`

Where "event_region" is a string and "match_regions" is a list of strings


Django Email Signals - Django App that Actually Solves a Business Problem

In my workplace we make a lot of Django apps and for a number of these Django apps, we configure a lots of emails to be sent.

Whenever something changes in the database that meets some condition we send an email. The emails have their own context and each email can be a time consuming to setup.

There has to be a better way I thought. And so, I built [django-email-signals](https://github.com/Salaah01/django-email-signals).

I build this app to be as plug-and-play as possible with minimal configuration. This Django app allows you to setup email signals right from the admin page

Here is a breakdown of what the app currently lets you do:

* Configure emails to be sent when some data in some model is changed.
* Set some constraints to determine if indeed an email can be sent.
* Either write up your email content when setting up a new email signal, or provide a path to a template.
* Be able to reference objects and attributes such  `instance.user.first_name`  right from where you would set your constraints or the email HTML itself.


Introducing Typesplainer: a python type-hint explainer

## What

Typesplainer is a Python type hint explainer that explains python type hints in plain English. It is very fast, accurate, and easy to use and understand. Available as a CLI, on the web, and as a Visual Studio Code extension

## Where

Website: https://typesplainer.herokuapp.com/\
CLI: https://pypi.org/project/typesplainer/\
Visual Studio Code extension (Alpha): https://marketplace.visualstudio.com/items?itemName=WasiMaster.typesplainer

## Why

Wondering WTF is an `Callable[[List[int]], Dict[int, List[Union[str, None]]]]`? typesplainer has got you covered. It's a callable that accepts a list of integers and returns a dictionary that maps integers onto a list of optional strings. Understanding type hints can be hard and time-consuming, especially if they are very big like the example above. This tool helps you understand things like that more easily and faster.

## How

Just use the cli if you want to use it anytime and anywhere. Use the website to test the tool before installing or if you want a graphical interface. And since the vscode extension is still in development, I won't recommend that at the moment.


Demystifying Apache Arrow: what is it and when should you use it?


Python Web Frameworks


The Boilerplate for Logging in Python

## Use this logging template in your next big project

Finding bugs is a common problem in any programming project. To make it easier to find bugs, you probably want to write some print statements to help you debug.

Is it helpful? yes. Is it the right way to track events in your code, especially in a big project? no.

Python has a built-in logging module that you can use to log messages. Logging not only helps you debug the issues in your code. It also helps you understand the flow of your code especially when you ship to production.

It is a very useful tool to identify how your code is behaving whether it is working as expected or not. If not, it can show you different hierarchies of how severe the issue is whether it is an error, a warning, or a debug mode.

Without having logging, it's difficult to keep your code maintainable for a long time. Especially when this code is mature.

In this tutorial, I'll show you a boilerplate for logging that you can use in your next project. Instead of looking at the documentation every time.

## Division Example
Let's take this division example especially when we divide by zero:
```python
def divide(dividend, divisor):
    try:
        return dividend / divisor
    except ZeroDivisionError:
        return "Zero Division error."

print(divide(6, 0))
```
In this case, when we divided 6 by 0 we returned a message string. This message shows that a zero division error during the `ZeroDivisionError` exception occurred.

What's the problem with that? The issue here is that we don't know when that happened and how severe the issue is. Is it a warning? an error? or just a piece of information you're printing to the console?

The built-in Python's `logging` module helps you better log your code with its features. Let's see how we can use it in this context:
```python
import logging

# Define a logger instance
logger = logging.getLogger(__name__)
# Define a stream handler for the console output
handler = logging.StreamHandler()

# Customize the formatter on the console
formatter = logging.Formatter(
    "%(asctime)s -  %(name)s: %(levelname)s - %(message)s",
    datefmt="%Y-%m-%d %H:%M:%S"
    )
# Add the formatter to the handler
handler.setFormatter(formatter)

# Add the stream handler to the logger that we will use
logger.addHandler(handler)
# Set the level of logging to be INFO instead of the default WARNING
logger.setLevel(logging.INFO)

def divide(dividend, divisor):
    try:
        logger.info(f"Dividing {dividend} by {divisor}")
        return dividend / divisor
    except ZeroDivisionError:
        logger.info("Zero Division error.")

print(divide(6, 0))
```
which would return helpful information like this:
```
2022-02-23 13:24:41 -  __main__: INFO - Dividing 6 by 0
2022-02-23 13:24:41 -  __main__: INFO - Zero Division error.
```
## Wrap Up
In this boilerplate, you've seen how to log messages to the console. You've formatted the logs to start with a date and time followed by the name of the module, level of logging, and the log message itself.

Check out the [logger module here](https://gist.github.com/EzzEddin/0e8c517a47e678da6a60cc21fdbc5788) and let me know if you have any feedback, thanks!


Python vs SQL for Data Analysis: comparing performance, functionality and dev XP

The clean division of data analysis labor between Python and SQL seems to be fading with tools like dbt, Snowpark and dask-sql. The article shared below compares the two languages in terms of performance, functionality and developer XP.

Quick summary:

**Performance**
Running SQL code on data warehouses is generally faster than Python for querying data and doing basic aggregations. This is because SQL queries move code to data instead of data to code. That said, parallel computing solutions like Dask and others that scale Python code to larger-than-memory datasets can significantly lower processing times compared to traditional libraries like pandas.

**Functionality**
SQL’s greatest strength is also its weakness: simplicity. For example, writing SQL code to perform iterative exploratory data analysis, data science or machine learning tasks can quickly get lengthy and hard to read. Python lets you write free-form experimental data analysis code and complex mathematical and/or ML code. The absence of a vibrant and reliable third-party library community for SQL is also a problem compared to Python.

**Developer XP**
Python makes debugging and unit-testing a lot easier and more reliable. While dbt has added code versioning by forcing the use of Git, SQL diffs are still harder to read and manipulate than diffs in Python IMO.

**Conclusion**
While it's tempting to frame the debate between SQL and Python as a stand-off, the two languages in fact excel at different parts of the data-processing pipeline. One potential rule of thumb to take from this is to **use SQL for simple queries that need to run fast** on a data warehouse, **dbt for organizing more complex SQL models**, and **Python with distributed computing libraries like Dask for free-form exploratory analysis and machine learning code** and/or code that needs to be reliably unit tested.

Full article:
[https://airbyte.com/blog/sql-vs-python-data-analysis](https://airbyte.com/blog/sql-vs-python-data-analysis)


Use Python to Transcribe an Audio File in an S3 Bucket in 3 Steps

Hey guys! I wrote a [mini-article](https://www.assemblyai.com/blog/transcribing-audio-files-in-an-s3-bucket-with-assemblyai/) on **how to transcribe an audio file in an S3 bucket in 3 simple steps**.

Figured it might be helpful for people learning to use Python, JSON, AWS, etc.!


Processing large JSON files in Python without running out memory


Python Class Constructors: Control Your Object Instantiation – Real Python