r/pythoncoding • • Aug 03 '21

Python Insider: Python 3.10.0rc1 is available

Thumbnail blog.python.org
16 Upvotes

r/pythoncoding • • Feb 19 '21

Pattern Matching Showdown: PEP 634 vs PEP 653

16 Upvotes

Python Enhancement Proposal (PEP) 634 is accepted for Python 3.10 a while ago. It provides a syntax for pattern matching. In a gross simplification, it gives Python its missing switch statement - on steroids. PEP 635 provides its motivation and rationale, along with some examples.

Enter PEP 653. Its authors write:

Pattern matching in Python, as described in PEP 634, is to be added to Python 3.10. Unfortunately, PEP 634 is not as precise about the semantics as it could be, nor does it allow classes sufficient control over how they match patterns.

This bold statement is backed up by pointing out the undefined behavior of PEP 634, and provides some examples where PEP 634 does not provide an easy answer.

That said, moving to a new syntax so soon after another one is introduced poses some downsides. First, there might be more to learn from the currently accepted implementation. Second, it sets a bad precedent that new features in CPython can be so short lived. This encourages programmers to give new features a wide berth, as their future is so uncertain and maintaining deprecated code is a pain.

Thoughts on both PEPs, pros and cons of accepting 653, of flaws with this new proposal that would require even a third contestant? Curious about your thoughts!


r/pythoncoding • • Jan 11 '21

fpdf2, the library to easily generate PDFs, got a new release

Thumbnail
github.com
16 Upvotes

r/pythoncoding • • Dec 07 '22

[META] State of the sub - share your feedback, if any

15 Upvotes

Greetings,

/r/Pythoncoding has slowly been growing and seeing new content and community members. As the end of the year approaches I'm curious if there's any feedback from the community.

One thing is about the complexity of submissions. Are you happy with what's posted? Is it too basic, or too strict? Share this and any other thoughts below!


r/pythoncoding • • Nov 09 '22

how does Python's built-in `endswith` using a tuple of suffixes rank against a trie-based alternative implementation? read the performance benchmarking using `timeit` and detailed analysis, including a concluding look at `endswith`'s cpython source code

Thumbnail
veryverbose.net
15 Upvotes

r/pythoncoding • • Aug 03 '22

eCharts for Python

Thumbnail
tech.marksblogg.com
15 Upvotes

r/pythoncoding • • Sep 06 '21

Crypto portfolio tracker implemented in Python

15 Upvotes

I've been trading crypto for a few months now and I've been frustrated by Coinbase's lack of portfolio management tools. It seems like there are some web-based services available that provide this capability, but they all require subscriptions and your portfolio's API keys -- a big red flag for me.

So I chose to develop my own toolset in Python. I'm going to document my process on my Publish0x blog. I want to share it here because it seems like there's a real desire from amateur crypto enthusiasts like myself to take more control over their crypto portfolios. I hope it helps!

https://www.publish0x.com/more-coffee-more-crypto/how-to-write-your-own-coinbase-pro-portfolio-manager-part-1-xjodqvk

The git repository is already public but its very bare bones, so I'll share it later. Stay tuned for more posts on authenticating your API keys, plotting portfolio performance, etc. Any recommendations or critiques are appreciated.


r/pythoncoding • • Aug 27 '21

PEP 668 -- Graceful cooperation between external and Python package managers

Thumbnail
python.org
15 Upvotes

r/pythoncoding • • May 18 '21

Why use an SQL query builder in the first place? (writing a query builder in 150 lines of Python)

Thumbnail death.andgravity.com
15 Upvotes

r/pythoncoding • • Dec 25 '25

Merry Christmas!

14 Upvotes
import os
import time
import random
import sys

# Constants for better readability
COLORS = {
    'green': "\033[32m",
    'bright_green': "\033[92m",
    'yellow': "\033[93m",
    'red': "\033[91m",
    'white': "\033[97m",
    'blue': "\033[94m",
    'reset': "\033[0m",
    'bold': "\033[1m"
}

def move_cursor(y, x):
    """Moves the terminal cursor to a specific row and column."""
    sys.stdout.write(f"\033[{y};{x}H")

def hide_cursor(): sys.stdout.write("\033[?25l")
def show_cursor(): sys.stdout.write("\033[?25h")

class FestiveTerminal:
    def __init__(self, height=15):
        self.height = height
        self.width = os.get_terminal_size().columns
        self.snowflakes = []
        self.tree_top_y = 5
        self.tree_center_x = self.width // 2

    def create_snowflake(self):
        """Generates a new snowflake at the top."""
        return [1, random.randint(1, self.width), random.choice(['*', '.', '+', '❄'])]

    def draw_tree(self):
        """Draws the static tree structure with dynamic lights."""
        cx = self.tree_center_x
        ty = self.tree_top_y
        
        # Star
        move_cursor(ty - 1, cx)
        print(f"{COLORS['yellow']}{COLORS['bold']}★{COLORS['reset']}")

        # Foliage
        for i in range(self.height):
            row = ty + i
            width = i 
            left_side = cx - width
            
            move_cursor(row, left_side)
            line = ""
            for _ in range(width * 2 + 1):
                if random.random() < 0.1:  # 10% chance for a glowing ornament
                    line += f"{random.choice([COLORS['red'], COLORS['yellow'], COLORS['white']])}o{COLORS['green']}"
                else:
                    line += "*"
            print(f"{COLORS['green']}{line}{COLORS['reset']}")

        # Trunk
        move_cursor(ty + self.height, cx - 1)
        print(f"{COLORS['yellow']}[###]{COLORS['reset']}")

    def update_snow(self):
        """Updates snowflake positions and adds new ones."""
        # Add new snow
        if len(self.snowflakes) < 50:
            self.snowflakes.append(self.create_snowflake())

        for flake in self.snowflakes:
            # Erase old position
            move_cursor(flake[0], flake[1])
            print(" ")
            
            # Update position
            flake[0] += 1 
            
            # Reset if it hits bottom or goes out of bounds
            if flake[0] >= self.height + 10:
                flake[0] = 1
                flake[1] = random.randint(1, self.width)
            
            # Draw new position
            move_cursor(flake[0], flake[1])
            print(f"{COLORS['white']}{flake[2]}{COLORS['reset']}")

    def run(self):
        os.system('cls' if os.name == 'nt' else 'clear')
        hide_cursor()
        try:
            while True:
                self.draw_tree()
                self.update_snow()
                
                # Center Message
                msg = "MERRY CHRISTMAS & HAPPY CODING"
                move_cursor(self.tree_top_y + self.height + 3, self.tree_center_x - len(msg)//2)
                print(f"{COLORS['bold']}{COLORS['red']}{msg}{COLORS['reset']}")
                
                sys.stdout.flush()
                time.sleep(0.15)
        except KeyboardInterrupt:
            show_cursor()
            os.system('cls' if os.name == 'nt' else 'clear')
            print("Holiday spirit deactivated. Goodbye!")

if __name__ == "__main__":
    app = FestiveTerminal(height=14)
    app.run()

r/pythoncoding • • Dec 23 '22

pythonetc: Posts about Python stdlib, syntax, and internals

Thumbnail
github.com
14 Upvotes

r/pythoncoding • • Jun 24 '22

Ultra-edge Detection system (snickometer) using LM393 Sound Sensor and python

Thumbnail
youtu.be
14 Upvotes

r/pythoncoding • • Apr 24 '22

Desktop Python Apps (Shortcuts and Environment variables+registers)

14 Upvotes

Handy and light python package, if you are developing desktop apps and are familiar with environment variables and shortcuts, did you realized that there are no packages that would make it easy for cross compatible and easy management of this stuff ?

After searching and making my own package i decided to make it public so it can potentially help somebody with the same stuff i was struggling before, feel free to check it out:Github: https://github.com/jiri-otoupal/pycrosskit

Currently I am rewriting this package to newer state and would be glad for anyone to add Mac support, if somebody want to contribute.

If you would star my repo for the work I do, it would make my day much better :)
I will be glad if it will make your life easier, Cheers !


r/pythoncoding • • Jan 10 '22

/r/pythoncoding Q1 2022 hiring thread

14 Upvotes

Overview

If you have open positions at your company for python developers and would like to hire from the /r/pythoncoding user base, please leave a comment detailing any open job listings at your company. Internships are also welcome.

Please reserve top level comments for those posting open positions.

Rules & Guidelines

Include the company name in the post; posts lacking a company name will be removed. Include the geographic location of the position along with the availability of relocation assistance or remote work.

  • If you are a third party recruiter, you must disclose this in your posting.

  • Please be thorough and upfront with the position details.

  • Use of non-hr'd (realistic) requirements is encouraged.

  • While it's fine to link to the position on your company's website, provide the important details in the comment.

  • Mention if applicants should apply officially through HR, or directly through you.

  • Please clearly list citizenship, visa, language, or other certification requirements.

This post format is blatantly stolen from /r/netsec (thanks guys!); for examples of effective job postings, you can browse some of their previous threads

Feedback

Feedback and suggestions are welcome, but please don't hijack this thread (use moderator mail instead.)


r/pythoncoding • • Jan 06 '22

Good Python Source Code

14 Upvotes

Hi guys. I'm putting together a curated index of high quality source code at goodsourcecode.org. The goal is to create a really nice collection of exemplary source code, searchable by language and concept tags, that developers can use to understand how different ideas are implemented in practice, and how those implementations interact with other components.

If anyone has any examples of good Python source code, please share!

The more detail the better. What makes the suggested source code good? This will inform what tags are used for indexing.


r/pythoncoding • • Dec 12 '21

String validation in Python

14 Upvotes

Hey there folks! I wanted to share with you a library I'm working working on (nothing innovative), and that is a string validator, similar, if not the same as the validator.js that is in the JavaScript ecosystem. The motivation for it was a lack of finding the right library that contains what I was searching for, and maybe I guess some more people out there might have this need as well. The library is far from over, however minor progress is made weekly.
The idea is to have all the string validation in one place and as optimised as possible. I was using type hinting within the project, maybe not so wise because it would limit Python versions for usage.
I hope that it will present some help, to someone who has the same need as I do. If any one wants to contribute, feel free to open a PR.
The reference to the project on GitHub → https://github.com/theteladras/py.validator


r/pythoncoding • • Oct 04 '21

Coverage 6.0 released

Thumbnail nedbatchelder.com
14 Upvotes

r/pythoncoding • • Oct 03 '21

Runtype 0.2 - faster than Pydantic, highly configurable, and with unique features for working with types at runtime.

Thumbnail
github.com
14 Upvotes

r/pythoncoding • • Aug 29 '21

Write an SQL query builder in 150 lines of Python!

Thumbnail death.andgravity.com
14 Upvotes

r/pythoncoding • • Aug 07 '21

What do you when you botch a release on PyPI

Thumbnail
snarky.ca
14 Upvotes

r/pythoncoding • • Jun 22 '21

Subclassing in Python Redux

Thumbnail
hynek.me
14 Upvotes

r/pythoncoding • • Mar 02 '21

Make tests a part of your app

14 Upvotes

My new article is out!

This time I want to discuss a pretty useful idea for library authors and their users: there are better ways to test your code!

I give three examples (in #python, but the idea itself applies to almost any language) of how user projects can be self-tested without actually writing any real test cases by the end-user. One is hypothetical about django and two examples are real and working: featuring deal and dry-python/returns.

Short example with deal:

import deal

@deal.pre(lambda a, b: a >= 0 and b >= 0)
@deal.raises(ZeroDivisionError)  # this function can raise if `b=0`, it is ok
def div(a: int, b: int) -> float:
    if a > 50:  # Custom, in real life this would be a bug in our logic:
        raise Exception('Oh no! Bug happened!')
    return a / b

This bug can be automatically found by writing a single line of test code: test_div = deal.cases(div). As easy as it gets!

From this article you will learn: -How to use property-based testing on the next level

  • How a simple decorator @deal.pre(lambda a, b: a >= 0 and b >= 0) can help you to generate hundreds of test cases with almost no effort

  • What "Monad laws as values" is all about and how dry-python/returns helps its users to build their own monads

I really like this idea! And I would appreciate your feedback on it. Link: https://sobolevn.me/2021/02/make-tests-a-part-of-your-app


r/pythoncoding • • Jan 05 '17

financial_life: A framework for analysing financial plans through simulations

Thumbnail
github.com
14 Upvotes

r/pythoncoding • • Dec 27 '22

An attempt to significantly reduce homelessness and poverty: I made an open source web application that helps people who are struggling find social services and donators in their area that will help them.

Thumbnail self.python
13 Upvotes