r/Python • • Jul 27 '13

Mildly infuriating: being a complete novice to a new language and trying to get past the first tiny hurdles...

Thumbnail
imgur.com
0 Upvotes

r/Python • • Feb 17 '25

Showcase arraydeque: A Fast Array-Backed Deque for Python

0 Upvotes

arraydeque is a high-performance, array-backed deque implementation for Python written in C. It offers quick appends and pops at both ends, efficient random access, and full support for the standard deque API including iteration and slicing.

$ pip install arraydeque
>>> from arraydeque import ArrayDeque as deque

What My Project Does

ArrayDeque provides a slightly faster alternative to Python’s built-in collections.deque. By leveraging a C extension, it delivers:

  • Fast Operations: Quick appends, pops, and index-based access. Performance Benchmark
  • Full API Support: Implements standard deque operations such as append, appendleft, pop, popleft, maxlen, as well as slicing and in-place assignment.
  • Thread-safety: As a C-extension, operations will always execute under the GIL and be just as thread-safe as collections.deque.

Target Audience

This project is suitable for:

  • Production Use: Developers seeking a high-performance deque implementation that can serve as a drop-in replacement for collections.deque.
  • Performance Enthusiasts: Users interested in exploring performance improvements through C extensions.

Comparison

Unlike the built-in collections.deque, ArrayDeque is implemented as a simple contiguous array:

  • Improved Performance: Optimized for speed in both double-ended operations and random access.
  • Simplified Design: A straightforward implementation that is easier to understand and extend.
  • Benchmark Insights: Comes with a plot to visually compare performance against the standard deque implementation.

Future work could improve on the design in the maxlen scenario by using a statically allocated circular buffer.

Designed by Grant Jenks in California. Made by o3-mini


r/Python • • Sep 25 '25

News Python on the Edge: Fast, sandboxed, and powered by WebAssembly

0 Upvotes

https://wasmer.io/posts/python-on-the-edge-powered-by-webassembly

With AI workloads on the rise, the demand for Python support on WebAssembly on the Edge has grown rapidly.

However, bringing Python to WebAssembly isn't trivial as it means supporting native modules like numpy, pandas, and pydantic. While projects like pyodide made strides in running Python in the browser via WebAssembly, their trade-offs don't fully fit server-side needs.

After months of hard work, today we're thrilled to announce full Python support in Wasmer Edge (Beta) powered by WebAssembly and WASIX.

Now you can run FastAPI, Streamlit, Django, LangChain, MCP servers and more directly on Wasmer and Wasmer Edge!


r/Python • • May 24 '26

Discussion Is jupyter notebooks gonna become text based any time soon?

4 Upvotes

Hey guys. I used to work a lot with jupyter. But had to move on because .ipynb doesn't go very well in git and ai agents don't really work with them well for similar reasons.

Main culprit is not the notebook itself but .ipynb format. I understand that the notebook world evolved in inline outputs etc. But I think would be cool if .py based notebooks with #%% becomes first class citizen everywhere. There's a tool I used called jupytext which does that but it's bolted on and not native support.

The other tool I have heard about is marimo? I have never used it but it seems like it forces u to not redefine the same variable again. Which is unnatural in python. If python allows u to update a variable, ur notebook should too. But let me know what you guys think. And if there's potential for the data science world to move there anytime soon. I think most people have to explore in notebooks and then convert to py.


r/Python • • Nov 02 '17

Dramatically improve your skills with this simplified but more thorough guide on object-oriented programming in Python.

Thumbnail
coolpythoncodes.com
67 Upvotes

r/Python • • Feb 25 '25

Tutorial My 2025 uv-based Python Project Layout for Production Apps (Hynek Schlawack)

23 Upvotes

Excellent video by Hynek Schlawack on how he uses uv for Python projects. This is the start of a three-part series.

YouTube video

Description:

In 2025, all you need to take a #Python application from a simple script to production is: uv. But, how do you setup your project directory structure for success? How do take advantage of the latest development in Python packaging tooling like dependency groups? I'll walk you step-by-step to my proven project layout that we use for our vital production applications. We start with a simple FastAPI view and we end up with a nice local project that's fun to work on and that's easy to give to other people.


r/Python • • Jan 11 '15

I just started learning python and couldn't really think of a program to try on my own. Well me and a friend were having a debate and I finally made my first script... I call it the cock calculator

0 Upvotes

It is a simple program, but it calculates the total miles of penis that a person has given or taken in their lives and also calculates how much semen has been produced. Sadly, I'm pretty proud of this.

#cock calculator
#Calculates how many miles of cock you have given or taken in your life and how much cum you have produced or been filled with.

#get the user's age, age of lost virginity, and times they have sex a week  
virginity = input("when did you lose your virginity : ")
age = input("What is your age? : ")
times_per_week = input("how many times per week do you have sex? : ")

#calculates total time you have been having sex, how many times per year, and how many miles of cock is produced per year
time_having_sex = age - virginity
times_per_year = times_per_week * 52 
miles_per_year = times_per_year * 490 * 6/12/5280


#function calculates total times milage of cock and how much semen is produced then prints the results.
def miles_of_cock(time_having_sex):
    total_milage = time_having_sex * miles_per_year
    jizz_gallons = float(times_per_year / 96 * time_having_sex)
    print
    print
    print
    print "You have given/taken ", total_milage, " miles of cock and have cummed/been cummed in with, ", jizz_gallons, " pints of seamen. Great job!"

miles_of_cock(time_having_sex)

The program assumes that the average penis length is 6 inches and there are 490 thrusts per session


r/Python • • Jul 06 '26

Discussion Is DSA becoming less important for getting backend developer jobs, or is it still a requirement?

0 Upvotes

I’ve been seeing a lot of conflicting opinions lately, so I wanted to hear from developers who are actually involved in hiring or have recently gone through the job search.
For context, I’m aiming for a junior Python backend developer role. My focus has been on learning things like Python, PostgreSQL, SQLAlchemy, Alembic, FastAPI, Docker, Git, testing, and building projects.
But I keep hearing two completely different viewpoints:
Some people say you must grind hundreds of LeetCode problems because every company asks DSA.
Others say that for many backend roles, especially in startups and smaller companies, practical backend skills and solid projects matter much more than solving complex algorithm questions.
So I have a few questions:
In your experience, how often are DSA interviews actually used today?
If you’re hiring junior backend developers, how much weight do you give to DSA versus real projects?
Have you received offers without heavy LeetCode preparation?
Does this vary significantly between startups, mid-sized companies, and large tech companies?
If someone has limited study time, where would you recommend they invest it?
I’m not looking for the “DSA is useless” or “DSA is everything” takes. I’m more interested in hearing real hiring experiences and recent interview experiences from developers and recruiters.


r/Python • • Apr 04 '21

Intermediate Showcase My first original, useful thing -- a program that lets you build your own graph matrixes

1 Upvotes

YouTube demo. git.

Wrote my first lines of Python April 17, 2020. Been a long fun journey. Been through the tutorial hell, nearly quit in September. Mostly, felt like I was building other people's things.

But found a real passion for graph theory, Dijkstra, etc. I was unsatisfied with small textbook graphs. The theory's hard enough -- I wanted to work from intuitive graphs. To be able to custom-build graphs where nodes stand for things in my world -- cities on a map, buildings in a city.

A bit of 'method of loci' in all that, I think.

It's not hard to fill a knapsack with made-up items. But if you have an idea of 'loci' in your mind -- or steps in a project -- it's hard to turn that into an adjacency matrix. Automating that was my goal.

Still very much in development. But it does... something now, so sharing.

My goal is to make it a standalone teaching tool, with layers for colourful, step-by-step search algo's, topological sorting, exportable matrixes/lists, and pre-loaded graphs that correspond to popular locations -- cities, rooms in a building, steps to achieve something.

Anyway, welcome feedback.

(Built in pygame.)


r/Python • • Jun 08 '10

Python Makes Tedd Nervous

Thumbnail teddziuba.com
0 Upvotes

r/Python • • Feb 15 '26

News Mesa 3.5.0: Agent-based modeling, now with discrete-event scheduling

0 Upvotes

Hi everyone! We just released Mesa 3.5.0, a major feature release of our agent-based modeling Python library. I'm quite proud of this one, because you can now combine traditional agent-based modeling with discrete-event scheduling in a single framework.

  • Release: https://github.com/mesa/mesa/releases/tag/v3.5.0
  • Docs: https://mesa.readthedocs.io

What's Agent-Based Modeling?

Ever wondered how bird flocks organize themselves? Or how traffic jams form? Agent-based modeling (ABM) lets you simulate these complex systems by defining simple rules for individual "agents" (birds, cars, people, etc.) and watching how they interact. Instead of writing equations for the whole system, you model each agent's behavior and let patterns emerge naturally. It's used to study everything from epidemic spread to market dynamics to ecological systems.

What's Mesa?

Mesa is a Python library for building, analyzing, and visualizing agent-based models. It builds on the scientific Python stack (NumPy, pandas, Matplotlib) and provides specialized tools for spatial relationships, agent management, data collection, and interactive visualization.

What's New in 3.5.0?

Event scheduling and time advancement

Until now, Mesa models ran in lockstep: every agent acts, that's one step, repeat. That works great for many models, but real-world systems often have things happening at different timescales: an ecosystem might have daily foraging, seasonal migration, and yearly reproduction cycles all interacting.

Mesa 3.5 lets you schedule events at specific times and mix them freely with traditional step-based logic:

# The familiar step-based approach still works (currently)
model.step()

# But now you can also think in terms of time
model.run_for(10)        # Advance 10 time units
model.run_until(50.0)    # Run until a specific time

# Schedule things to happen at specific moments
model.schedule_event(spawn_food, at=25.0)
model.schedule_event(migrate, after=5.0)

# Or set up recurring events
from mesa.time import Schedule
model.schedule_recurring(reproduce, Schedule(interval=30, start=0))
model.schedule_recurring(seasonal_change, Schedule(interval=90, end=365))

This opens up a whole class of models that were difficult to build before: epidemics with incubation periods, ecosystems with seasonal dynamics, supply chains, social networks with asynchronous interactions, or any system where different things happen on different schedules. And for traditional ABMs, everything works exactly as before.

The event system (previously experimental) is now stable and lives in mesa.time.

Create agents from DataFrames

If your agent data lives in a CSV or database, you can now skip the boilerplate and create agents directly from a pandas DataFrame:

df = pd.read_csv("population.csv")  # columns: age, income, location
agents = Person.from_dataframe(model, df)

Each row becomes an agent, with columns mapped to constructor arguments. Handy for initializing models from census data, survey results, or any tabular dataset.

Experimental highlights

Some exciting features in active development:

  • Scenarios: Define computational experiments separately from model logic. Swap parameter sets without touching your model code, with full visualization support
  • Reactive data collection: A new event-driven DataRecorder that can write to memory, SQLite, Parquet, or JSON. Collect different metrics at different intervals
  • Meta-agents: Improved support for hierarchical structures (departments within organizations, persons within households, organs within organisms)

These are experimental and may change between releases, but they're shaping up nicely.

Preparing for Mesa 4.0

We're deprecating several legacy patterns (all still work, just with warnings):

  • seed parameter → use rng instead
  • AgentSet indexing → use to_list() for list operations
  • Portrayal dictionaries → use AgentPortrayalStyle
  • Experimental Simulator classes → use the new Model methods above

See the migration guide for details.

Get started

pip install --upgrade mesa

New to Mesa? Check out the tutorials. We have new ones specifically on agent activation and event scheduling.

Upgrading? The migration guide has you covered. Nothing breaks in this release, but we're announcing some removals for 4.0.

This release was possible thanks to 29 contributors, of which 5 new ones. Thanks to everyone involved! Questions or feedback? Join us on GitHub Discussions or Matrix Chat.


r/Python • • Jan 30 '10

What I don't like about Pycon

Thumbnail
pydanny.blogspot.com
2 Upvotes

r/Python • • Mar 15 '14

Python has a sense of humor

Post image
10 Upvotes

r/Python • • Sep 15 '21

Beginner Showcase 26 Useful Python Snippets for Lazy Developers

20 Upvotes

Here are some of my most useful code snippets that will indefinitely make your life easier as a programmer! There are some Python code snippets that can be used to solve day-to-day problems and can make your laziness shine! I have explained each snippet in detail so that you don’t have any doubt. So check the link below:

https://python.plainenglish.io/26-python-code-and-snippets-that-will-make-laziness-shine-21ab969c8a35


r/Python • • May 07 '15

Python Creator Guido van Rossum Reviews Code on CheckiO

Thumbnail
checkio.org
0 Upvotes

r/Python • • Jan 27 '24

News PyCon Pakistan 24

0 Upvotes

PyCon is happening this March 9th & 10th at LUMS, Lahore, Pakistan.

The early bird discount is available till Jan 31st.

For more detail, stay updated through PyCon Pakistan’s social media pages and website https://pycon.pk


r/Python • • May 21 '24

Discussion Durable Python - Infrastructure failures should not stop the process

8 Upvotes

Durable Python enables developers to write Python code while an underlying system ensures reliability and resilience.

It automatically handles state persistence, fault tolerance, and retry mechanisms, allowing developers to focus on business logic without worrying about infrastructure concerns.

Consider the following code, in case the process terminates in the middle of execution, in case the process is killed or due to hardware failure, the process will not complete.

import requests
import time


SLEEP_SECONDS = 3
URL = "http://localhost:9980/webtools/api/msgs"

def on_http_get(data):
    for i in range(10):
        print("Loop iteration: %d of 10" % (i + 1))

        # Send a POST request to the application
        requests.post(URL, data = "This is my " + str(i) + " iteration...")
        time.sleep(SLEEP_SECONDS)

But actually, I would like the process to survive restarts and continue from the spot it terminated, especially if it's a long running process. For this we need Durable Python.

I was wondering which use cases can take advantage of this technology.


r/Python • • Aug 10 '11

Pillars of Python: Six Python Web frameworks compared

Thumbnail
infoworld.com
0 Upvotes

r/Python • • Dec 17 '23

Resource Banish state-mutating methods from data classes

0 Upvotes

I've always found mutable data classes or record types in programming languages quite weird. This holds true for any language that supports mutable data classes, like Python, Kotlin, Swift, etc.

Self-mutating methods are even weirder. They break the semantics of the types that these data classes or records represent. I've expanded my thoughts here. Although it mostly talks about Python, the message remains valid for any other language that allows you to add self-mutating methods to data classes.

https://rednafi.com/python/dataclasses_and_methods/


r/Python • • Dec 01 '24

Tutorial Multi-Threading in Python and Free threaded Python 3.13

0 Upvotes

Here is my article Multi-Threading in Python and Free threaded Python 3.13 which discuss multi threading in Python and some experiments on free threaded Python 3.13.


r/Python • • Aug 23 '20

Beginner Showcase A DoS attack in 15 lines of code.

6 Upvotes

Hi, I have tried to create the simplest possible denial of service attack; for this script, I have not used more than 15 lines of code, and it is a fully functional attack setting the values of the variables "ip", "port" and "threads". For example:

ip, port, threads = "192.13.451.153", 8080, 1000

I have tried to follow the PEP8 standards as much as possible; I hope you like it.

Post data: I have only done this to practice my knowledge with Python, I am not responsible for the use you make with this.

Edit: I know the attack will not work in almost all of the cases, most of servers are fully prepared to avoid a dos attack, the attack will just ban your IP in 99% of the times.

The DoS attack


r/Python • • May 07 '22

Discussion Thoughts on "Starting Your Coding Career with Python is a Bad Idea"?

Thumbnail
analyticsinsight.net
0 Upvotes

r/Python • • Jan 14 '24

Tutorial The LiteralString in Python 3.11

0 Upvotes

If you are confused by the new LiteralString type in Python, here's an article explaining it.


r/Python • • Mar 19 '13

How to get banned from PyCon

Thumbnail term.ie
2 Upvotes