r/pythontips • • Oct 13 '21

Module [MODULE] Python library to download reddit videos , images and even gallery images with a single post url without needing your own praw bot and without manual installation of ffmpeg

36 Upvotes

I recently published a python package called RedDownloader it's published on pypi. I decided to publish it after not finding a simplified way to download reddit videos with sound and gallery posts. Most of the libraries don't have a support for gallery posts some require you to have your own praw bot and some require manual installation of ffmpeg but with RedDownloader all you need is a post url and all is taken care of. Downloading is just a single line of code and can be fit into a varitey of projects.

I am the author of this package and plan out to expand the package's capabilities in coming time


r/pythontips • • Sep 25 '21

Python3_Specific Python development environment in docker. Includes VS-code IDE, job scheduler, and other tools for linting, testing, auto-documentation and profiling.

36 Upvotes

https://github.com/bluxmit/alnoda-workspaces/tree/main/workspaces/python-workspace

This image helped me a lot to isolate the complete environments in the docker containers, easily switch between projects, and backups python projects together with the entire environments! Also, we made a common dev environment for the team.


r/pythontips • • Aug 30 '21

Syntax 7 Levels of Using F-Strings in Python

36 Upvotes

By this article, I totally understand the F-strings in Python.


r/pythontips • • Aug 08 '21

Short_Video Branding QR Code in Python but with a twist

36 Upvotes

In this tutorial You can create QR code and have a brand image in the center. But also it will automatically find the color of the brand image pixel and generate the same color QR code as the Brand is using. So you do not need to find the color separately of what ever brand you are using.

Here is the video Demo:- https://youtu.be/OFMDQTyQAC4


r/pythontips • • Jul 18 '21

Python3_Specific Python best practices book recommendation

36 Upvotes

Hi fellow redditers,

I'm software developer coming for C++ background,
I'm looking for book(s) for python best practices that similar to the Cpp's Bible (effective C++) ..
Any recommendations?

Thanks,


r/pythontips • • Jul 14 '21

Short_Video Zoom call Remove Background filter using Python and OpenCV

36 Upvotes

this is a 10-minute video where I have explained how you can replace the background in a live video stream with a still image using python and OpenCV, we have also used cvzone and mediapipe this background removal also works with noisy backgrounds


r/pythontips • • Jul 07 '21

Module using regular expressions with the Re library

36 Upvotes

first you have to know the character class

\d = Any numeric digit from 0 to 9.

\D = Any character that is not a numeric digit from 0 to 9.

\w = Any letter, numeric digit, or the underscore character.(Think of this as matching “word” characters.)

\W = Any character that is not a letter, numeric digit, or the underscore character.

\s = Any space, tab, or newline character. (Think of this as matching “space” characters.)

\S = Any character that is not a space, tab, or newline.

an example of date validation:

import re

regex = re.compile(r"\d\d/\d\d/\d\d\d\d")  
match = regex.search("Mary's date of birth: 10/04/2001")

print(match.group())

First we have to import the library is, a library comes by default in python, I used re.compile and as a parameter I passed a String with the pattern we want to look for, the first \d\d ​​represent the two digits of the month, then I typed a /, then \d\d ​​for the day, then a /, then \d\d\d\d for the year, this function returns a Regex object.

On the other line I use regex.search and pass the String where I want to search for the pattern, regex in this case is the name of the variable where I stored the pattern. This will return a Match object.

On the other line I used print(match.group()). The Match object's group method will only return the first match of the pattern in the String. The output of this code:

10/04/2001

But, if there is more than one date in the String, it will only return the first, to solve this we use the findall() method, this method returns a list with all matches of the pattern found:

import re

regex = re.compile(r"\d\d/\d\d/\d\d\d\d")  
result = regex.findall("Mary's birth date: 10/04/2001, John's birth date: 04/21/1989")

print(result)

the output of this code:

['10/04/2001', '04/21/1989']

you separate your pattern into different groups using parentheses (), as in the example:

import re

regex = re.compile(r"(\d\d)/(\d\d)/(\d\d\d\d)")  
match = regex.search("Mary's birth date: 10/04/2001")

print(match.group())

the output of this code is 10/04/2001, but if we pass 1 as a parameter of match.group() the output will be 10 because it is the first match of the first group of the String, if we pass 2 as a parameter the output will be 04 and if you pass 3 as a parameter the output will be 2001.

If you use findall() on patterns that have groups, the output will be a list and in that list will have a tuple with each group's match:

import re

regex = re.compile(r"(\d\d)/(\d\d)/(\d\d\d\d)")  
result = regex.findall("Mary's birth date: 10/04/2001")

print(result)

the output of this code:

[('10', '04', '2001')]

all of this below works with groups too:

you can make patterns with a certain amount of characters using braces {}, for example, we want to do a validation of a number that has 10 digits, instead of typing \d 10 times, we can do that using \d{10}:

import re

regex = re.compile(r"\d{10}")  
result = regex.findall("a random book has 6295618392 letters")

print(result)

the output of this code:

['6295618392']

You can set a minimum and a maximum of characters too, for example if you want a number of 5 to 10 digits is just typing \d{5,10}, you can also not set a minimum and not set a maximum, number with 10 digits or less \d{,10}, number with 10 digits or more \d{10,}.

Use ? to make it optional, for example:

import re

regex = re.compile(r"books?")  
result = regex.findall("Mary has only one book")

print(result)

the output of this code:

['book']

Or:

import re

regex = re.compile(r"books?")  
result = regex.findall("Mary has many books")

print(result)

the output of this code:

['books']

Since ? is after s, s is optional, making the String "book" or the String "books" valid.

Using | you can search for either a String or another String, for example, if you type Mary|John it will validate the String Mary or the String John, whichever comes first.

import re

regex = re.compile(r"Mary|John")

result = regex.findall("Mary has many books")  
print(result)

result = regex.findall("John has many books")  
print(result)

the output of this code:

['Mary']

['John']

Using + means it has to have 1 or more characters or groups if you are using it in groups, in this example I first use the String "ILovePython", after I use the String "I Love Python":

import re

regex = re.compile(r"\s+Python")

result = regex.findall("ILovePython")  
print(result)

result = regex.findall("I Love Python")  
print(result)

the output of this code:

[]

[' Python']

in the first print, result is equal to [] because a space character was not found before the String Python, in the second print, as a space character was found before the String Python, result is equal to [' Python'].

* is similar to +, the only difference is that using * can be optional, that is, 0 or more characters, whereas with + it must have at least 1 character:

import re

regex = re.compile(r"\s*Python")

result = regex.findall("ILovePython")  
print(result)

result = regex.findall("I Love Python")  
print(result)

the output of this code:

['Python']

[' Python']

On the first print it returned ['Python'], though not without a space before the word.

You can create your own character classes using []:

import re

regex = re.compile(r"[aeiouAEIOU]")

result = regex.findall("Hello World")  
print(result)

the output of this code:

['e', 'o', 'o']

[aeiouAEIOU] represents 1 character, the character can be one of those inside the [], that is, all the vowels, that's why the output shows all the vowels of the string "Hello World"

using ^ before, the reverse is valid:

import re

regex = re.compile(r"[^aeiouAEIOU]")

result = regex.findall("Hello World")  
print(result)

the output of this code:

['H', 'l', 'l', ' ', 'W', 'r', 'l', 'd']

that is, characters that are not the ones inside the [] which in the example is aeiouAEIOU are the ones that will be valid.

can be used [a-zA-Z] to represent all characters of the alphabet.

can be used [0-9] to represent digits from 0 to 9, but using that or \d is the same thing, can be used to represent smaller intervals like [0-5].

you can also use ^ at the beginning of your patterns, this will indicate that the String has to contain the pattern at its beginning:

import re

regex = re.compile(r"^Hello")

result = regex.findall("Hello, World")  
print(result)

result = regex.findall("World, Hello")  
print(result)

the output of this code:

['Hello']

[]

in the first print ['Hello'] is returned because "Hello" was found at the beginning of the search string.

you can use $ at the end of the pattern, this indicates that the String has to contain the pattern at its end:

import re

regex = re.compile(r"World$")

result = regex.findall("Hello, World")  
print(result)

result = regex.findall("World, Hello")  
print(result)

the output of this code:

['World']

[]

in the first print ['World'] is returned because "World" was found at the end of the search string.

The . is called a wildcard character, that is, it is equivalent to any single character:

import re

regex = re.compile(r".at")

result = regex.findall("the cat use the hat")  
print(result)

the output of this code:

['cat', 'hat']

Using re.VERBOSE as a second parameter of the re.compile() method, you can add line breaks, spaces and comments to your pattern, using re.I or re.IGNORECASE you validate both uppercase and lowercase letters:

import re

regex = re.compile(r"""
    ^=SUM\(
	
	    ([A-X][A-F][A-D]|[A-Z]{1,2})
	    (10[0-4][0-8][0-5][0-7][0-6]|[0-9]{2,6}|[1-9])?

    (:([A-X][A-F][A-D]|[A-Z]{1,2})
    (10[0-4][0-8][0-5][0-7][0-6]|[0-9]{2,6}|[1-9])?)?
	
    (
    ,([A-X][A-F][A-D]|[A-Z]{1,2})
    (10[0-4][0-8][0-5][0-7][0-6]|[0-9]{2,6}|[1-9])?
		
    (:([A-X][A-F][A-D]|[A-Z]{1,2})
    (10[0-4][0-8][0-5][0-7][0-6]|[0-9]{2,6}|[1-9])?)?
    )*
    	\)$
    """,
    re.I | re.VERBOSE
)

This validates Excel's SUM formula, validates =sum(a1:b5) and also =SUM(A1:B5), that's because I used re.I, I used re.VERBOSE so I can add line breaks, I can use both at the same time using | to separate re.I from re.VERBOSE.

Using re.DOTALL as the second parameter of re.compile(), the . becomes equivalent to line breaks as well:

import re

regex = re.compile(r".new_line", re.DOTALL)

result = regex.findall("""first_line
    new_line
""")  
print(result)

the output of this code:

[' new_line]

There was a line break after first_line, the . corresponded to this line break, then it was returned line break with the String new_line.


r/pythontips • • Jun 17 '21

Python3_Specific Web Scraping With Selenium

36 Upvotes

I am currently learning selenium to bring my ideas to life. However, I couldn't use it on a site called "German Word of the Day"
Can someone help me scraping this page?
https://www.transparent.com/word-of-the-day/today/german.html


r/pythontips • • Apr 22 '21

Short_Video Python vs Java - this is why people like Python (amongst other things)

36 Upvotes

I mean, if you can implement such a task like reversing a list in one line, programming becomes easier.

I made a quick comparison between the two languages

https://youtu.be/tPjwAOsc5ks


r/pythontips • • Mar 20 '21

Syntax How do you find the square roots of a umber using code?

36 Upvotes

I've started a python programming class and have had not too many problems with it. We moved on to square roots and I got lost. One of the problems I'm confused on is one where the user puts in a number (negative or positive) and gets the square root.

Here's a example:

Enter a number: -16

4.0

If you could help I would really appreciate it.


r/pythontips • • Jan 30 '21

Module How to server for a py game

36 Upvotes

Hey ! Im actually making py game but i wanted to know if any of you guys have any tips to set à multiplayer mode. This a very simple game who just gave word to anyone when the game start. If you want to know more about the project leave a comment. Ps: sorry for my English ^


r/pythontips • • Jan 20 '21

Short_Video Write your first test in Selenium Python

36 Upvotes

Let's take a look at how to write your first browser test in Python using the SeleniumBase framework -

You can check out my article here to learn more about the SeleniumBase framework.


r/pythontips • • Dec 16 '20

Short_Video A small example how you can interact with an api

36 Upvotes

This video shows how to create a package that creates memes using an API from imgflip: https://youtu.be/aVLLV2fkAnM


r/pythontips • • May 21 '20

Module Need help for learning python

36 Upvotes

I have just started learning python,i need some where(sites or forums) that gives project examples with its codes from begginer to advanced.i realy need to learn how to use what i have learnt. Thanks in advance.


r/pythontips • • Mar 11 '22

Standard_Lib Python Programming Course for Free

35 Upvotes

Does anybody know of any good free resource to use to learn python??


r/pythontips • • Jan 02 '22

Python3_Specific Validations in Python using Metaprogramming Decorators- Advanced Python

35 Upvotes

Validations in Python using Metaprogramming Decorators- Advanced Python

A #Decorator is a special kind of declaration that can apply to a function to enhance its functionality*.* This is also called known as #metaprogramming. Here we are trying to modify the functionality of a function on compile time. Metaprogramming is a cool concept in ant programing language. It can be used to apply certain checks before executing the actual function. 
Let’s try to understand the use-case with an example.

Learn More: Validations in Python using Metaprogramming Decorators


r/pythontips • • Sep 15 '21

Data_Science How to Create Dummy Data in Python

35 Upvotes

In this article, you will learn a different way to create Dummy data by using the Faker python package. Visit here: https://www.thinkdataanalytics.com/how-to-create-dummy-data-in-python/


r/pythontips • • Sep 05 '21

Short_Video Virtual Mouse using Python (Controlling cursor with hand motion and clicking with finger)

35 Upvotes

In this short tutorial, i have explained how to create a python program that can control cursor movement with hand action and click with snapping fingers


r/pythontips • • Jul 29 '21

Syntax Write Clearer Python Code with Type Hints

35 Upvotes

Good morning developers! Today I wanna share with you a great tip to make you code way more understandable and self-documenting: type hinting.

Type hinting is the process of annotating the type a certain symbol (variable, function, method...) should be. Not only does it help you remember in the future what format and data type a variable is supposed to be, but it also is a blessing for whoever might read your source code. In addition to that, type hinting gives your IDE's type checker more context to work with, leading to better static type analysis, thus highliting those hateful dumb TypeErrors.

Static types are a blessing, not a curse. They are one of the reasons statically typed languages are so much used in production codebases, making your code much more explicit and maintainable.

Check out this brief tutorial on type hinting with Python: https://betterprogramming.pub/how-to-write-clearer-python-code-with-type-hints-330216291b7c

I personally think type hints should be in every Python codebase, but beware that they might not always be the best choice in terms of readability. By using them you will develop a natural feeling for how and when to use them. They will also prepare you to learn other static languages more easily, which I really think you should.

I'd appreciate any feedback on this tutorial. Have a nice day!


r/pythontips • • Jun 21 '21

Module Finished Coursera Google Automation IT with Python Certificate, now what?

35 Upvotes

So I just finished my "Professional" certification sponsored by Google learning a range of software developer stuff such as:

  • cloud, debugging, bash

  • python, json, OOP

  • VM, linux and ubuntu

I wanted to ask you guys is there any resource that connects me with employers once I finish? My dad keeps yelling at me and saying that he read there was a whole network with employers linked to the class that I should be 'contacting.' It is a bit frustrating when he is yelling at me to "use the network that I paid for!" when I can't find anything. QUOTE from Coursera, " When you complete all of the courses in the program, you'll earn a Certificate to share with your professional network as well as unlock access to career support resources to help you kickstart your new career. Many Professional Certificates have hiring partners that recognize the Professional Certificate credential." So where can I find hiring partners and career support!?

I just started applying for jobs with the Cert now on my resume. Once you finish, it quickly unsubscribes you and seemed like everything was finished. I received no emails stating anything about companies looking to speak with me, nor did I receive any info on where to start applying USING the new Automation IT Python Certificate. He keeps screaming at me because I'm not using their resources since he saw that the Google Class advertises employers looking for that specific certification. IMO, I still feel incredibly underqualified to apply for even Jr. Python Dev jobs.

Is there anything else to utilize from Coursera/ Google Cert where I can find a list of companies that are hiring within that field? Am I missing something?


r/pythontips • • Apr 15 '21

Short_Video Python app in docker that creates a diy server side digital frame app

35 Upvotes

I built a small app with python and docker and now you can use those tablets and phones as web clients for a server side picture frame. Just load images in a folder, run the code and you are all set. No more paperweights. Code and docker hub links are in the desc. Step by step instructions in the video

https://youtu.be/QvFtiO_ONf4


r/pythontips • • Jun 03 '20

Syntax Test your regexp online

35 Upvotes

Undo & redo, save & share, learn, build, & test: https://regexr.com/


r/pythontips • • Sep 11 '19

Meta We are learning Python at /r/EruditeClub. Please join us to discuss the process and learn from each other!

35 Upvotes

Hello!

I am a mod over at /r/EruditeClub. It is a sub where we pick a new skill to learn each month and this month we are learning Python.

We are checking into Python oriented subs to ask for advice, have subscribers join our discussion, and hopefully spread a little learning.

Looking forward to seeing you there or receiving tips here in this post.

Thanks!


r/pythontips • • Oct 22 '23

Module List of Python projects with source code

34 Upvotes

Here is my contribution to Python beginners a list of Python mini projects with source code. If you are also interested in contributing to Python mini projects you can also add to the website.

if you are interested in checking out my contribution you can follow the below link also if you are interested please don't forget to share

https://ideasorblogs.in/python-projects/

I hope this will be useful for beginners