r/pythontips • • Aug 15 '19

Automate the Criminal Stuff - Part 2

43 Upvotes

In this episode offer an introduction to web scrapping. There is a ton of great data out there on the web, so let's grab it and use it in our criminal enterprises!

https://youtu.be/8pd7C7W2B-k

Update! I just posted Part 3: https://youtu.be/a5JHnuLeLMM

If you missed Part 1: https://youtu.be/ZxCZPGpqcL4

If you have any questions let me know, I'll try to answer them here or in a future video!


r/pythontips • • Aug 30 '18

Python3_Specific New Playground and Cheatsheet for Learning Python

43 Upvotes

I'm learning Python and I decided to create a repository where I could put Python script samples with standard Python syntax, structures and statements examples just to be able to quickly recap how to use this or that feature of the language.

Here is what I've got.

This is a collection of Python scripts that are split by topics and contain code examples with explanations, different use cases and links to further readings.

It is a playground because you may change or add the code to see how it works and test it out using assertions. It also allows you to lint the code you've wrote and check if it fits to Python code style guide. Altogether it might make your learning process to be more interactive and it might help you to keep code quality pretty high from very beginning.

It is a cheatsheet because you may get back to these code examples once you want to recap the syntax of standard Python statements and constructions. Also because the code is full of assertions you'll be able to see expected functions/statements output right away without launching them.

How to Use The Repo

Each Python script in the repository has the following structure:

"""Lists  <--- Name of the topic here

# @see: https://www.learnpython.org/en/Lists  <-- Link to further readings goes here

Here might go more detailed explanation of the current topic (i.e. general info about Lists).
"""


def test_list_type():
    """Explanation of sub-topic goes here.
    
    Each file contains test functions that illustrate sub-topics (i.e. lists type, lists methods).
    """
    
    # Here is an example of how to build a list.  <-- Comments here explain the action
    squares = [1, 4, 9, 16, 25]
    
    # Lists can be indexed and sliced. 
    # Indexing returns the item.
    assert squares[0] == 1  # <-- Assertions here illustrate the result.
    # Slicing returns a new list.
    assert squares[-3:] == [9, 16, 25]  # <-- Assertions here illustrate the result.

So normally you might want to do the following:

  • Find the topic you're want to learn or recap.

  • Read comments and/or documentation that is linked in each script's docstring (as in example above).

  • Look at code examples and assertions to see usage examples and expected output.

  • Change code or add new assertions to see how things work.

  • Run tests and lint the code to see if it work and is written correctly.

Table of Contents

  1. Getting Started

  2. Operators

  3. Data Types

  4. Control Flow

  5. Functions

  6. Classes

  7. Modules

  8. Errors and Exceptions

  9. Files

  10. Additions

  11. Brief Tour of the Standard Libraries

I hope you find this repository helpful!


r/pythontips • • Feb 27 '25

Python3_Specific VsCode VS PyCharm

42 Upvotes

In your experience, what is the best IDE for programming in Python? And for wich use cases? (Ignore the flair)


r/pythontips • • Mar 30 '24

Data_Science I shared a Data Science learning playlist on YouTube (20+ courses and projects)

42 Upvotes

Hello, I shared a playlist named "Learning Data Science in 2024" and I have more than 20 videos on that playlist. It is completely beginner friendly and there are courses for data analysis, data visualization and machine learning. I am leaving the link below, have a great day! https://youtube.com/playlist?list=PLTsu3dft3CWiow7L7WrCd27ohlra_5PGH&si=GA4DTY8mrBnlGsIr


r/pythontips • • Jul 29 '22

Module I have zero knowledge in python

42 Upvotes

Any recommended youtuber where I can learn the basics of python? TIA and God bless!


r/pythontips • • Jan 30 '22

Syntax Can you make 9 lines of code into 1 ?

42 Upvotes

Is there a way I can make those 10 line of code into 1 ?

cleanfhstring1 = fhstring.replace(",", "")
cleanfhstring2 = cleanfhstring1.replace(".", "")
cleanfhstring3 = cleanfhstring2.replace("?", "")
cleanfhstring4 = cleanfhstring3.replace("!", "")
cleanfhstring5 = cleanfhstring4.replace(":", "")
cleanfhstring6 = cleanfhstring5.replace(";", "")
cleanfhstring7 = cleanfhstring6.replace("-", "")
cleanfhstring8 = cleanfhstring7.replace(")", "")
cleanfhstring9 = cleanfhstring8.replace("(", "")
cleanfhstring10 = cleanfhstring9.replace("\n", " ")


r/pythontips • • Jun 16 '21

Module How should I continue learning python?

42 Upvotes

I started learning a couple of weeks ago but now I don’t know how to continue. Everything I did until now was what I read programmers called imperative programming. Should I try learning object-oriented programming, functional programming or is it too technical? It seems learning these it’s helpful to fully understand the basic concepts but I’m lost lol


r/pythontips • • May 16 '20

Python3_Specific whatsapp bot for replying your messages

42 Upvotes

i have created a bot to reply whatsapp messages for you , i included while True loop ,so the program will not end ,so after you run the following code ,the bot will automatically reply to all until you manually close the window , Try my code and suggest me to improve it in a better way

To install required packages

Run pip install selenium in the command prompt

To install chrome webdriver

click here for chrome webdriver

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

#replace with your chrome webdriver location

driver = webdriver.Chrome(r'C:\Users\Home\Downloads\chromedriver_win32\chromedriver.exe')
driver.get("https://web.whatsapp.com/")

input("Press anything after QR scan")
time.sleep(5)


names = [""]#add the person's name whom who want to reply automatically
            #add as many persons you want   

while True:
    for name in names:
        person = driver.find_element_by_xpath('//span[@title = "{}"]'.format(name))
        person.click()

        msg_got = driver.find_elements_by_css_selector("span.selectable-text.invisible-space.copyable-text")
        msg = [message.text for message in msg_got]
        if msg[-1] == "Hi":
            reply = driver.find_elements_by_class_name("_2S1VP")
            reply[1].clear()
            reply[1].send_keys("hi\n tell me")
            reply[1].send_keys(Keys.RETURN)

if you find any difficulty in copying this code, i have also given the pastebin link , to open https://pastebin.com/xG6Ej1iJ

thankyou


r/pythontips • • Oct 17 '19

Ultimate Python Projects with Source Code – Practice Top Projects in Python

42 Upvotes

Python Projects with Source Code

Looking to build a career in Python? Want to improve your resume with multiple personal projects on it? Then this blog of Python projects with source code is for you. You earlier read about the top 5 data science projects; now, we bring you 6 projects implementing data science with Python. In this blog, you’ll find the entire code to all the projects. Read on to give your data science/ Python career a head-start.

List of amazing Python Projects with source code –

Why do Projects in Python?

In an interview, a resume with projects shows interest and sincerity. Spending time on personal projects ultimately proves helpful for your career. In this blog of python projects, we try our best to include different data science and machine learning libraries of Python to give you a better experience.

Top Python Projects with Source Code

Let’s start discussing python projects with source code –

1. Driver Drowsiness Detection with OpenCV and Keras

📷

Driving while the driver feels drowsy is extremely dangerous and thousands of accidents happen each year because the driver fell asleep. The drowsiness detection system can save a life by alerting the driver when he/she feels drowsy.

Read More


r/pythontips • • Oct 09 '19

Turn Python Scripts into Beautiful ML Tools

42 Upvotes

r/pythontips • • Feb 22 '19

Python Web Scraping & Crawling for Beginners | Youtube Playlist

42 Upvotes

I am making a video series on Scrapy ( python library for web scraping ) which you can check out below

Youtube Playlist - https://www.youtube.com/playlist?list=PLhTjy8cBISEqkN-5Ku_kXG4QW33sxQo0t

Have already uploaded 21 videos and will be the rest on alternate days.


r/pythontips • • Jun 29 '16

Syntax Beware of object References!

42 Upvotes

If someone wants to create a 10 * 10 matrix of zeros in Python, they may attempt to do this:

>>> row = [0] * 10
>>> print row
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

>>> matrix = [row] * 10
>>> print matrix
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]

All looks well so far! This was a nice Pythonic way to do this right?

Wrong.

This person overlooked the fact that each of the 10 row objects are just references to that first row. So when this person wants to set the middle item in the matrix to 1, they end up setting the middle element in every row to 1.

>>> matrix[4][4] = 1   #set middle item to 1
>>> print matrix
[[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]]

A better way to do this would be to create a row, and then repeat the act of creating that row 10 times:

>>> matrix = [[0 for x in range(10)] for y in range(10)]
>>> print matrix
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]

>>> matrix[4][4] = 1   #set middle item to 1
>>> print matrix
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]

r/pythontips • • Jun 03 '16

piphub

42 Upvotes

Not exactly a Python tip, but I shared this recently in /r/Python thread and it seems like it is relatively unknown, so I thought I'd share it here:

You can pip install a git repository directly from a url using the git+ prefix. For example, you can install the requests directly from the github repository like: pip install git+https://github.com/kennethreitz/requests.git. I believe there is also an svn+ prefix if you want that (Edit: Google tells me you can also do hg or bzr) , and if you just use a url it installs source archives.

Now you don't need to bother uploading everything to pypi. Have fun!


r/pythontips • • Jan 08 '23

Python3_Specific F-String In Python - A Modern Way To Perform String Interpolation

41 Upvotes

The f in f-string can also stand for fast because of its better performance than the other formatting methods and it has several advantages.

f-string is also called Formatted String literal and is a convenient way to interpolate variables into the string.

Here's how to interpolate strings using f-string👇👇

F-String In Python - A Modern Way To Perform String Interpolation


r/pythontips • • Nov 14 '22

Data_Science Best introductory Data Science Book using Python?

41 Upvotes

Back in 2016 when I started coding in Python and doing data analysis on it, the “Python Data Science Handbook” by Jake Van Der Plas was regarded as the best possible intro to Data Science in Python.

Although the messages in the book are mostly timeless, best practices and packages evolve. Sometimes people ask me how to start and I still recommend that book.

If you had to pick one, what “Data Science with Python” book would you recommend for the newcomers? Thanks!


r/pythontips • • Sep 23 '21

Data_Science 15 Must-Know Python String Methods

41 Upvotes

Python is a great language. It is relatively easy to learn and has an intuitive syntax. The rich selection of libraries also contribute to the popularity and success of Python. Visit here: https://www.thinkdataanalytics.com/python-string-methods/


r/pythontips • • Jul 30 '21

Data_Science Top 3 Statistical Paradoxes in Data Science

41 Upvotes

Observation bias and sub-group differences generate statistical paradoxes.

Observation bias and sub-group differences can easily produce statistical paradoxes in any data science application. Ignoring these elements can therefore completely undermine the conclusions of our analysis. Visit here: https://www.thinkdataanalytics.com/top-3-statistical-paradoxes-in-data-science/


r/pythontips • • May 15 '21

Algorithms My first project in python

41 Upvotes

I just did my first project in python and I don't have a lot of other experiences either.

This morning I decided to make a project and I though about doing the game hangman.

I would love if some of you could give me your tips, advice and tell me what you think about the way I did my project.

Is it too hard to understand while reading my code, is it normal that it took me 6 hours to only do that? etc...

I would like any comments you could give about this first project of mine.

Thanks !!

Here's the link to my GitHub : https://github.com/cbelangerstpierre/Hang-man


r/pythontips • • Sep 02 '20

Meta The best way to read a file in python is to not read it at all - an intuitive understanding to Python Iteration Protocol.

41 Upvotes

https://www.bharathkreddy.com/post/best-way-to-read-a-file-is-not-to-read-it-at-all-python-iteration-protocol

I write about pythons Iteration protocol and how intuitively understanding of this helps understand things like iterators, generators etc.


r/pythontips • • Aug 15 '20

Gnubesoft: So many Intermediate Python Tips!

41 Upvotes

My Intermediate Python tutorial series is just about wrapping up. In this latest video I'm integrating the networking portion with the rest of the app, and making sure everything is SUPER asynchronous. I include a lot of great Intermediate Python tips and concepts in here, all with practical real world examples.

https://www.youtube.com/watch?v=ZR7eF8obUsQ

You don't need to have seen the rest of the series to follow the tips, but it might help!

https://www.youtube.com/watch?v=QG-KvTZwxfc&list=PLMD4SGMb7qkVt4drPdDxImhhGw3ZNuzbB


r/pythontips • • Apr 18 '23

Meta I had a python interview and that was so bad

40 Upvotes

Hi I'm python engineer since 2017. I have experience working with Django, drf, react, SQL, unit testing. And some dude sent me a live core python challenge, I forgot some basic stuff and I ask him the use of read the docs, and he doesn't let me do that. I don't pass to the next interview then they sent me an email with the bad news and some courses about python, docker, CI/CD, cloud... wtf lol. What do you think about this, ask me whatever you want.


r/pythontips • • Mar 10 '23

Short_Video 🧩 [UPDATE] drag-and-drop GUI builder inside VS Code

40 Upvotes

https://youtu.be/vP51dsenc70

hi everyone, excited to share more updates and get opinions!

to recap, i'm building a VS Code extension to create Python UIs with drag-and-drop. to simplify building an entire web app inside VS Code using just Python, no other languages or frameworks :)

this is a quick video that shows the initial Dash and how the binds between widgets and the code work. it's already available in the vs code marketplace, but still very much a work in progress!

i'd like to know what you guys use to build web apps, if you use a combination of tools. if so, which? and do you feel it involves too many services/steps? thanks!


r/pythontips • • Nov 16 '22

Standard_Lib Python memory managment

40 Upvotes

If you want to learn something about python memory management you might interestde in this https://towardsdatascience.com/how-to-mitigate-memory-issues-in-python-c791b2c5ce7e?sk=7e1c6cb380c73bd9b5d5c97b668d88a2


r/pythontips • • Dec 18 '21

Long_video The Complete SQL Bootcamp 2022: Go from Zero to Hero

40 Upvotes