r/pythontips • • Jun 12 '21

Algorithms [News] VSCode extension "Blockman" to Highlight nested code blocks with boxes

70 Upvotes

Check out my VSCode extension - Blockman, took me 6 months to build. Please help me promote/share/rate if you like it. You can customize block colors, depth, turn on/off focus, curly/square/round brackets, tags, python indentation and more.....

https://marketplace.visualstudio.com/items?itemName=leodevbro.blockman

Supports Python, R, Go, PHP, JavaScript, JSX, TypeScript, TSX, C, C#, C++, Java, HTML, CSS and more...

This post in react.js community:

https://www.reddit.com/r/reactjs/comments/nwjr0b/idea_highlight_nested_code_blocks_with_boxes/


r/pythontips • • Feb 19 '21

Short_Video I never knew events were THIS powerful - A Python observer pattern tutorial

70 Upvotes

Event systems are incredibly powerful: this video is inspired by a software design problem I recently encountered, and using an event-based approach not only solved my problem, but also lead to new insights: https://youtu.be/oNalXg67XEE


r/pythontips • • Sep 20 '20

Algorithms Built an Intelligent file organizer that reads your file storing pattern.

70 Upvotes

A few weeks back, I found a post over this Reddit page about a Python project that organizes your file.

I thought of adding a little intelligence to it. Thus I published this python package known as Filezen: https://pypi.org/project/Filezen/. This package has an Advanced Scanning Mode which reads your file storing pattern(more info about it in the project README). Using that pattern it moves the unorganized files into the folder it should belong.

It also scans the child directories recursively(the depth of scanning can be configured). Also, you can specify different input folder(where your cluttered files are) and output folder(where you want it to finally move).

Also, it has a Normal Scanning Mode where it simply creates different directories for different filetypes

Checkout Github for detailed info: GitHub: https://github.com/ab-anand/Filezen

If you like it do give the repo a star. And feel free to fork and contribute <3


r/pythontips • • May 18 '26

Standard_Lib Why "é" == "é" can be False in Python

69 Upvotes

Here’s a Unicode gotcha that can cause very confusing bugs in Python:

Two strings can look the same on screen, but still be different internally:

import unicodedata

a = "é"          # single code point: U+00E9
b = "e\u0301"   # "e" + combining acute accent

print(a)
print(b)

print(a == b)
# False

print(len(a))
# 1

print(len(b))
# 2

They look the same, but Python sees different sequences of Unicode code points.

You can inspect what is really inside the strings with repr() and unicodedata.name():

import unicodedata

for char in "e\u0301":
    print(repr(char), unicodedata.name(char))

Output:

'e' LATIN SMALL LETTER E
'́' COMBINING ACUTE ACCENT

To compare these strings more safely, normalize them first:

import unicodedata

a = "é"
b = "e\u0301"

a_normalized = unicodedata.normalize("NFC", a)
b_normalized = unicodedata.normalize("NFC", b)

print(a_normalized == b_normalized)
# True

NFC converts text into a composed form when possible, so "e" + combining accent becomes the single composed character "é".

This is especially useful when dealing with user input, copied text, filenames, search, imported data, or text from multiple languages.

Another related problem: invisible characters.

For example, a zero-width space can silently break comparisons:

text = "hello\u200b"

print(text == "hello")
# False

print(text)
# hello

print(repr(text))
# 'hello\u200b'

The regular print() output can hide what is going on, butrepr() makes the invisible character visible.

You can read a more in-depth explanation here:

https://pythonkoans.substack.com/p/koan-15-the-invisible-ink


r/pythontips • • Feb 10 '23

Python3_Specific Announcing the release of my new book "Python Frenzy: 50 fun and simple projects for beginners" - a comedic guide for Python beginners! Complete with GitHub Code

69 Upvotes

Hey there my fellow Python enthusiasts!

Hold on to your hats, because I've got some exciting news to share with you all! After what felt like a million cups of coffee, a few all-nighters, and a whole lot of laughter, my book "Python Frenzy: 50 fun and simple projects for beginners" is finally here!

I wrote this book with one goal in mind: to help new Python developers like yourself to jumpstart your Python journey. I wanted to create a resource that not only teaches you how to code, but also has a bit of humor and personality to make the learning process more enjoyable.

The book is jam-packed with 50 simple yet fun projects that you can dive into, no matter what your skill level is. I cover everything from building a simple calculator to creating a weather app and even a job board. Trust me, these projects will give you the confidence you need to take on even bigger and better projects.

And the best part? The code for each project is included in the book, so you don't have to worry about typing out everything yourself, and also the code will be available through a link provided in the book to the completed code on GitHub.

So, what are you waiting for? If you're looking for a fun and easy way to learn Python, this book is for you. And don't worry, I'll be there every step of the way, cracking jokes and making sure you don't get too overwhelmed.

Check it out here on Amazon https://www.amazon.com/dp/B0BV9G1J2X

Thanks for all your support, and I hope you enjoy the book!


r/pythontips • • Mar 06 '22

Python3_Specific Adding a sense of humor to your Matplotlib plots using Matplotlib's XKCD feature!

69 Upvotes

In this blog post, I explain how to use Matplotlib's XKCD feature and show you some examples of how it can help you create funny, semi-sarcastic plots! :) 

https://lucytalksdata.com/how-to-create-semi-sarcastic-plots-using-matplotlib-xkcd-feature/


r/pythontips • • Jul 30 '19

Guide to building a Space Invader Game using Python | YouTube Playlist

69 Upvotes

I have just created this series on Python Game Development using Pygame. Have already uploaded 15 videos on creating a Space Invader game and will be uploading more.

You can check it out by clicking the the link below.

YouTube Playlist - Building a Space Invader Game using Python


r/pythontips • • Jun 02 '21

Data_Science Pyodide: A Project Aimed At Providing The Complete Python Data Science Stack Running Entirely In The Browser

68 Upvotes

Pyodide, a Mozilla’s independent community-driven project, provides a full Python data science stack running entirely in the browser. It uses the CPython 3.8 interpreter compiled to WebAssembly and uses Python, NumPy, Pandas, Matplotlib, SciPy, and more in Iodide, an experimental interactive scientific computing environment for the web.

Pyodide can be used in any context where it is necessary to run Python inside a web browser with full access to the Web APIs. The latest release note mentions that Pyodide converted the Python 3.8 runtime to WebAssembly and the Python scientific stack, including Pandas for data analysis, NumPy for scientific computing, and SciPy for scientific and technical computing, Matplotlib for visualization, and scikit-learn for machine learning.

At the time of the release, 75 packages are currently available. Pure Python wheels can also be installed from the PyPi Python package manager. Python 0.17 additionally provides transparent conversion of objects between Python and JavaScript.

Full Article: https://www.marktechpost.com/2021/06/01/pyodide-a-project-aimed-at-providing-the-complete-python-data-science-stack-running-entirely-in-the-browser/

Github: https://github.com/pyodide/pyodide


r/pythontips • • Oct 11 '19

10 Python File System Methods You Should Know

68 Upvotes

r/pythontips • • Mar 01 '24

Module What is the best place online to learn Python?

67 Upvotes

I’m a new beginner here. Followed a YouTube tutorial to get some basics, but I wanted to know if there’s anywhere better, or specific tutorials/youtube guides that the community thinks are really helpful.

Also, are there any good sites that offer excersises for practice?


r/pythontips • • Apr 09 '21

Module I started Python 10min ago and i already face my first Problem

67 Upvotes

Hi there :)

i hope i got the right flair..
Im new into programming and bought ''Python for Dummies'' since Python is supposed to be really beginner friendly.
Long story short here is my Problem:

The book sais i should write the following in Python:

>>>print ''Hello World''!

and this is what i got:

Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> print Hello World

File "<stdin>", line 1

print Hello World

^

SyntaxError: Missing parentheses in call to 'print'. Did you mean print(Hello World)?

>>> print ''Hello World!''

File "<stdin>", line 1

print ''Hello World!''

^

SyntaxError: Missing parentheses in call to 'print'. Did you mean print(''Hello World!'')?

>>> print (Hello World!)

File "<stdin>", line 1

print (Hello World!)

^

SyntaxError: invalid syntax

>>> print (''Hello World!'')

File "<stdin>", line 1

print (''Hello World!'')

^

SyntaxError: invalid syntax

>>>

if im correct, in every sentence is an error, but my book doesnt help with that.
i really hope someone can help me so i can continue with my book :3


r/pythontips • • Oct 19 '23

Module What's the coolest thing you have built using python

66 Upvotes

I'm a beginning learning python would love to know what are few project you have built using python.

Also it will help me to imagine the possibilities with python.


r/pythontips • • May 12 '21

Syntax The Fun of Using Punctuation in Python

66 Upvotes

Python is a very elegant programming language. Even just a simple punctuation may has very fancy tricks to use it better.

Here I list some interesting articles that talk about them:

  1. Ellipsis(...): 3 Uses of the Ellipsis in Python

  2. Asterisk(*): 5 Uses of Asterisks in Python

  3. Underscore(_): Four Usage Scenarios of Underscores in Python

Do you have any other interesting ideas about using punctuation in Python?


r/pythontips • • Mar 25 '21

Module Wanna performance test your Python code?

66 Upvotes

I made a library which can help you profile and test your Python code for performance. Allowing you to add performance validations to your tests. Link to the repo down below :) :

https://github.com/JoeyHendricks/QuickPotato


r/pythontips • • Mar 09 '21

Standard_Lib TIL enumerate takes an optional start argument

66 Upvotes

This means you can write

>>> iterable = ['foo', 'bar', 'spam']
>>> for index, item in enumerate(iterable, start=1):
...     print(index, item)
...
1 foo
2 bar
3 spam

All this time I had been using

for index, item in zip(itertools.count(1), iterable):
    ...

r/pythontips • • Jan 19 '21

Python3_Specific Python String Formatting - A definitive guide

66 Upvotes

Last week, I finished blogging about Python Strings.

Alot of topics were covered. But my fav is the String Formatting Guide. It covers 4 different ways of String Formatting nand a comparison of their execution times. Check out the guide here.


r/pythontips • • Sep 12 '18

Python Cheatsheet Website - pythoncheatsheet.org

66 Upvotes

Anyone can forget how to make character classes for a regex, slice a list or do a for loop. This cheat sheet tries to provide a basic reference for beginner and advanced developers, lower the entry barrier for newcomers and help veterans refresh the old tricks.

pythoncheatsheet.org

GitHub Project

Hope this is of help. Have a nice day =)

Edit: For some reason, the mobile version on chrome and safari is messed up, so prefer Firefox for now to use the quick search and the return to top button (or zoom out in chrome)


r/pythontips • • Jun 03 '16

Syntax Use parenthesis to wrap long strings

66 Upvotes

Sometimes we have that long text to write in a single line

LONG_TEXT = "this is a very long text written in just one line of code"

But sometimes it is better to use parenthesis syntax to have a better readability and to fit the 80 chars limit.

LONG_TEXT = (
   'this is '  # no commas here!
   'a very '
   'long text '
   'written in '
   'multiple lines of code'    
)

Sometimes it is useful.

The caveat is that if someone thinks it is a tuple and adds , in the end of each line, LONG_TEXT will be a sequence of strings.

LONG_TEXT = (
   'this is ',
   ...
)

r/pythontips • • Mar 12 '23

Long_video 25 Tips/Tricks to Write Better Python Code!

65 Upvotes

I created a long video on youtube pertaining to 25 tips to help you write better code in Python, this can help you in a professional setting, or in coding interviews. These tips include ways to improve the readability/maintainability of your code, improve efficiency, and learn aspects of the Python language you may have never heard of!

There are many tips which I summarize here:

  • Organize Imports Properly

  • Learn to Use PDB

  • Use the new Match/Case Statements

  • Learn about the Bisect Library

  • Learn about the Walrus Operator

  • Know when to use Enumerate over Range

  • Utilize Numpy for Efficiency

  • cProfile for finding Bottlenecks

  • Catch-all Unpacking to improve readability

  • Prefer f-strings over other string formatting methods

  • Naming Variables properly

  • Know when to use Generators over Lists

  • .get() Method to help with dictionaries

  • Specific Exceptions as opposed to broad exceptions

  • .zip() Method when iterating over multiple lists can help

  • Loops with Else Statements, not a very well-known feature in Python

  • Write Docstrings for complicated functions in practice

  • Be cautious with Python Dict Order

  • List Comprehension better practice

  • Use Dictionary Comprehension, a lot of people do not do this for some reason

  • Avoid one-line if/loops (seen a lot in hackerrank and leetcode)

  • Don’t check for empty containers/sequences, use "if not" instead

  • Split Long Lines of more than 79 chars

  • Add new line to the end of a file always in accordance with pep8

  • … Practice these points in your projects and share with teammates in code reviews :)

Would really appreciate anyone watching the video. I definitely think it can help new beginners. If you like such content please subscribe to the channel it would mean a lot!

Here is the video on youtube: https://www.youtube.com/watch?v=2U98PgL-kuI

Channel is here: https://www.youtube.com/@mmshilleh

Of course, comments are always appreciated, thanks Reddit!


r/pythontips • • Dec 26 '21

Data_Science 5 Useful Pandas Methods You May Not Know Existed - Part I

65 Upvotes

This blog post will introduce you to 5 lesser known Pandas features that will boost your productivity with this awesome library!

https://lucytalksdata.com/5-useful-pandas-methods-you-may-not-know-existed-part-1/


r/pythontips • • Apr 11 '21

Short_Video Daily Python3 recipes for beginners

65 Upvotes

I would like to share with you a series of Python3 recipes that I have recently started publishing. I hope it is of your interest and it can be very useful to you.

https://youtu.be/R9unPviiPSw


r/pythontips • • Jun 20 '20

Python3_Specific New Features in Python 3.9

65 Upvotes

Python3.9 released on June 20, 2020. it's really cool.

I really liked below three new features

  1. Dictionary Union Operators

  2. Type Hinting

  3. Two New String Methods

Demo link:- https://youtu.be/Dsl6VhemyZc


r/pythontips • • Apr 12 '23

Data_Science Web Scraping with Python step by step - most common libs, tips and code snippets in a pro scraper master class

64 Upvotes

r/pythontips • • Sep 08 '21

Syntax SIMPLIFY GREATER THAN - AND - LESS THAN STATEMENTS

64 Upvotes

I was today years old when I realized

if x > 10 and x < 20:

can be written as

if 10<x<20:

I'm not just dumb, I'm also slow