r/pythontips • • Nov 25 '21

Python3_Specific python exercises

51 Upvotes

Hello,

where can I solve exercises for free? I used eabit but I saw you need to get a pro account.


r/pythontips • • Jul 20 '21

Module Speed Up your Python Codebases with C Extensions

51 Upvotes

We all know Python is slow and C is fast. What if you could combine the power of C with the simplicity of Python?

C extensions are exactly for that. They let you write functions and objects directly in C or C++ and import them from your Python script as they were a module.

The only downside is that they are not very well documented. When I had to learn them, there was little to no resource on how to do so. Old tutorials and even the official documentation were outdated and I had to go on by trial and error and reading lone and unclear forum threads.

This article is comprised of an overview on C extensions and why and where to use them. It also contains a simple working example with source code and the steps to build an extension.

https://betterprogramming.pub/speed-up-your-python-codebases-with-c-extensions-94859875eb70

I hope you will find this resource helpful. And what do you think, should C extensions be the norm in Python codebases?


r/pythontips • • Aug 20 '20

Meta I (16) am a python programmer. How to use this skill to make money online?

51 Upvotes

Hey ! I'm 16 and I'm a python programmer. I started learning a few years ago and I now can develop various things with python (chatbots, tools, web servers, etc). How could I use this skill to make money online ? I tried to sell custom Discord Bots on Fiverr but nobody came after a few months with a very clean and cheap service. Any advices where to start ? What do I need to learn ? Where do I need to search ? Thanks a lot, I could really use some extra money right now and I'm ready to work hard for that.


r/pythontips • • Dec 06 '19

Intermediate Python: Asynchronous GUIs are Easy in Python

51 Upvotes

My YouTube tutorial series is finally ready to advance past the newbie territory into the fun stuff!

The next set of videos will be covering Intermediate concepts as we build a highly customizable Dropbox clone.

The first video is out today, showing off Asynchronous programming and desktop GUI development. Both of which are easy in Python!

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


r/pythontips • • Apr 17 '19

Web Scraping with Beautiful Soup & Python - A Beginner's Project

51 Upvotes

Hi guys, a week or two ago I made a post about web scraping as a great first step to learning to code and specifically to learn python. You can really be off the ground making something of practical utility with very little time invested.

Although the last example was great I wanted to show everyone how to make a project that can actually be useful in someway using some of this information. I personally find that the best way to learn is by doing something that I can find some practical usefulness in.

So, this time around I wanted to show you guys a truly practical intro project that you can get started on and something similar to what I have been paid for in the past. Now this project is a simplified version of what I made because I can't give away proprietary code for clients for free. That said, it should get you going down the road to building something that can be very practical.

Video Tutorial Link - https://www.youtube.com/watch?v=-31Or1HSmyo

Our Project:

This project is going to show you guys how you can very quickly and simply create a tool that will monitor a Shopify website by accessing the hidden API, and then (in part 2) automatically purchase any good (including rare limited release goods) from the store as soon as they are available.

The first video will use the hidden API plus requests and beautiful soup with python to get information and monitor for goods. The second video will show you how you can make a purchase automatically with basic web automation using python and selenium.

Why This Matters:

There is a large market for rare collectible shoes that is currently booming. Me and my partner have been contracted multiple times to build systems similar (but slightly more complex) than this in the past and paid good money for it.

If you can start with the basic example that we show here, you may be able to get more contracting type work with python, start a small buy and resell business or just learn some practical points of a project.

Whatever you choose to do with the information is up to you!

I really hope you all love the content as always, part 2 should be up and posted within the next day or two. So if you like our content it would mean a lot to us if you were to subscribe to our channel :)

Also feel free to let us know what you think about the series in the comments below. Did you get stuck and need help getting unstuck? Feel free to ask and we will do our best to answer!


r/pythontips • • May 29 '21

Python3_Specific Read WhatsApp messages using Python and selenium

50 Upvotes

Automate whatsapp with python doesn't mean only sending messages, so here we go for reading as well! 📄

A blog series to Read WhatsApp messages using Python and use that in your chatbot

Here's the link👇🏻

https://highontechs.com/chatbot/read-whatsapp-messages-using-python-selenium/


r/pythontips • • May 31 '20

Short_Video Using Google Translate API in Python | Python Tips and Tricks

50 Upvotes

Hello Guys,

I hope you are doing great.

I hope that you are safe and in home learning python.

How can we integrate Google translate based applications in our python projects?

There is a cool library by google called googletrans which allow us do exactly the same.

If u are interested, You can learn about that from here.. https://youtu.be/RRVbg5cQcjM

Now, where you might use this googletrans.

You might be developing some application which requires you to show the interface in multiple languages to users from different language. or you can come up with your own use case.

Thank you so much for taking your time to read this post.


r/pythontips • • Nov 30 '19

I finally did! Musician finally crosses over to programmer and makes her first program - voice tuner.

50 Upvotes

So first off a big thanks to everyone who commented and helped inspire me to accomplish this, and an especially big thank you to u/dfpena83 for your guidance to finally cross the finish line. As it seems like they’re a few people interested in my last post, I wanted to post an update for everyone.

Background: I’m a music student/teacher who wants to learn how to program a vocal tuner to help my students visualize music. After posting a question about how to make such a program, I got lots of suggestions that I looked into. Most of them were too complicated or did not allow me to make what I had pictured in my head.

u/dfpena83 contacted me to let me know that he thought a program he made, called StremeCoder, would be perfect for me. He even gave me a free copy and helped solve a few problems I had while figuring out how to use StremeCoder. I was surprised by how much making everything more visual helped me!

Here's YouTube clip to show it off in action! >>> https://www.youtube.com/watch?v=iPOCdZKargUz <<<

Feel free to DM or post any questions you have. Thanks everyone :)

**Original post here**

https://www.reddit.com/r/MusicEd/comments/dxmdrt/musician_looking_for_help_to_take_what_ive/


r/pythontips • • Mar 08 '19

​Python *args and **kwargs Made Easy

50 Upvotes

*args and **kwargs may seem scary, but the truth is that they are not that difficult to grasp and have the power to grant your functions with flexibility and readability.

​Python *args and **kwargs Made Easy


r/pythontips • • Feb 12 '22

Python3_Specific How to run your first program?!?

49 Upvotes

So, I just finished coding my first program ( a notepad) in python using pycharm. But I’m confused on how to use it. Everytime I save it, it’s just the script when run it. How do I finalize it and make I useable as if it was a note pad I downloaded.


r/pythontips • • Oct 04 '21

Short_Video I created this simple python program that will organise files into different folders according to file type

49 Upvotes

In this tutorialtutorial i have created a small python program that will create seperate folder for each file extension and then move all the files according to file type which will help create a clear folder


r/pythontips • • May 28 '21

Short_Video Tkinter Designer Video Tutorial Is Out ☄️

49 Upvotes

Thanks for the 700 Upvotes on previous post. Many people requested a video tutorial on using the program.

Tkinter Designer is created to speed up and beautify Python GUI Experience. It uses well know design software called Figma. Which makes creating Tkinter GUI in Python a piece of cake.

Of course you will need to tweak some things after it’s created but it saves a lot of time.

Here's the link to Video Tutorial:-Please ignore the Watermark.

https://youtu.be/mFjE2-rbpm8

Link to Repository :-

https://github.com/ParthJadhav/Tkinter-Designer

Thank you.


r/pythontips • • Sep 27 '20

Meta Is Python 3 Programming Specialization by Michigan University on Coursera, free for everyone to enroll and earn certificate? Can anyone please just confirm it on their Device?

49 Upvotes

The specialization has 5 courses. 5+1 certificates. Python 3 Programming


r/pythontips • • May 23 '20

Data_Science Master Python Imaging Library (Pillow in one tutorial).

49 Upvotes

Hello Guys , For those who wish to get started with Image processing in Python , here is the brief introduction to Python Imaging Library Pillow with detailed explanations and examples . Check it out

https://kalebujordan.com/a-brief-introduction-to-python-pillow/


r/pythontips • • May 15 '20

Data_Science Beginners guide to web scraping in Python

49 Upvotes

hello Guys I have clearly wrote this post to any one new to web scraping and wants to get started , It includes detailed explanations together with Simple Working demo project at the end , Hope you will find it interesting

https://kalebujordan.com/web-scraping-in-python-tutorial/


r/pythontips • • Aug 08 '16

Python3_Specific Merge dictionaries with {**a, **b} (in Python 3.5+)

49 Upvotes

Example:

>>> stuff = {'duck': 4, 'spam': 2}
>>> more_stuff = {'ribbon': 3, 'egg': 1}
>>> all_the_stuff = {**stuff, **more_stuff}
>>> all_the_stuff
{'egg': 1, 'duck': 4, 'spam': 2, 'ribbon': 3}

This is functionally equivalent to:

>>> all_the_stuff = {}
>>> all_the_stuff.update(stuff)
>>> all_the_stuff.update(more_stuff)
>>> all_the_stuff
{'egg': 1, 'duck': 4, 'spam': 2, 'ribbon': 3}

This feature came out of PEP 448.

This is actually a nudge to encourage everyone to upgrade to the latest Python 3.5! I know that not everyone can upgrade due to work difficulties and legacy code, but hopefully this feature will make you consider taking up that battle a little sooner.

If you cannot upgrade to Python 3.5, I wrote about a few other ways you can merge dictionaries in older versions of Python.


r/pythontips • • Jan 09 '23

Python3_Specific Turns out super() doesn't always call its parent method

48 Upvotes

Last week I learnt that super doesn't actually always call the method of a parent class. Instead, it respects the MRO of the original caller. I confessed my lack of knowledge at work and it turns out that everyone thought super called a parent method.

I presented the following code:

class A:
    def ping(self):
        print("ping from A")


class B(A):
    def ping(self):
        print("ping from B")
        super().ping()


class C(A):
    def ping(self):
        print("ping from C")
        super().ping()


class D(B, C):
    def ping(self):
        print("ping from D")
        super().ping()

I thought that D().ping() would output the following:

ping from D
ping from B
ping from A

Turns out it outputs the following instead:

ping from D
ping from B
ping from C
ping from A

If you already knew this, then nice! Otherwise, here is an article I've written that explains why and how super actually works:

https://python.plainenglish.io/youve-probably-misunderstood-python-inheritance-8052a84047a6


r/pythontips • • Oct 01 '22

Python3_Specific How to Learn Python as fast as Possible

48 Upvotes

Nowadays, Python is emerging as the most popular programming language, due to its uses and popularity every programming student want to learn python. Python is easy to learn, less coding, in-built libraries, these features of python makes it more popular. If you are a beginner and want to learn python then check this link, here I provided you roadmap that how you learn python and from where you learn python. One more special thing is that on the below link my A to Z Python notes are attached. Go fast and check the link: Learn Python For Free


r/pythontips • • Mar 02 '22

Data_Science Speed up Python code that uses NumPy

48 Upvotes

NumPy is the most popular Python module. It is popular for its N-dimensional array structure and suite of tools that can be used to create, modify, and process them. It also serves as the backbone for data structures provided by other popular modules including Pandas DataFrames, TensorFlow tensors, PyTorch tensors, and many others. Additionally, NumPy is written largely in C, which results in code that runs faster than traditional Python.

What if there were a simple way to find out if your Python code that uses NumPy could be sped up even further? Fortunately, there is!

ndarrays​

NumPy, like everything else, stores its data in memory. When a NumPy ndarray is written to memory, its contents are stored in row-major order by default. That is, elements in the same row are adjacent to one another in memory. This order is known as C contiguous, since it's how arrays are stored in memory by default in C.

import numpy as np

x = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])

print(x)

print(x.flags['C_CONTIGUOUS'])

In this case, each element of xis adjacent to its row neighbors in memory. Since memory can be visualized as a flat buffer, it looks like this:

That's straightforward enough. But did you know that you can set the contiguity of a NumPy array yourself? The other common contiguity is known as F contiguous, since it's how arrays are stored in memory by default in Fortran.

import numpy as np
y = np.asfortranarray(x)
print(x.flags['F_CONTIGUOUS'])

In this case, each element of y is adjacent to its column-wise neighbors in memory. That looks like this in a flat buffer:

Examples​

But what difference does the storage method make in terms of your Python code? It turns out that it can make a significant difference in terms of speed, depending on the dimensions of your data and the operations you want to perform. Code execution time decreases as values in memory get closer together.

Let's explore this with some simple examples.

import numpy as np
import time
row_major_array = np.random.uniform(0, 1, (10000, 2))
col_major_array = np.asfortranarray(np.array(row_major_array, copy = True))

print(row_major_array.flags['C_CONTIGUOUS'])
print(col_major_array.flags['F_CONTIGUOUS'])

start = time.time()
for i in range(1000):
    row_major_sum_along_rows = np.sum(row_major_array, axis = 0)
    row_major_sum_along_columns = np.sum(row_major_array, axis = 1)
end = time.time()
row_major_elapsed = (end - start) / 1000

start = time.time()
for i in range(1000):
    col_major_sum_along_rows = np.sum(col_major_array, axis = 0)
    col_major_sum_along_columns = np.sum(col_major_array, axis = 1)
end = time.time()
col_major_elapsed = (end - start) / 1000

print(f"Row major average time: {row_major_elapsed*1000} milli seconds.")
print(f"Col major average time: {col_major_elapsed*1000} milli seconds.")

LOG:

True 
True 
Row major average time: 0.2994 milli seconds. 
Col major average time: 0.02221 milli seconds.

We construct row_major_array and col_major_array , which are each two-dimensional arrays with 2 columns and 10,000 rows of random data between 0 and 1. The contiguity of the arrays are set in accordance with their naming. Then, the column-wise and row-wise sums are computed. We perform each of the two summations 1,000 times and time it, then divide the total time elapsed by 1,000 to see what the average computation time is.

Here, column major order is faster than row major order. The memory ordering of col_major_arrayis such that the distance between subsequent values needed for the summations is much smaller on average. This difference is significant. Let's try a similar operation on an array with far more rows than columns.

import numpy as np
import time
row_major_array = np.random.uniform(0, 1, (2, 10000))
col_major_array = np.asfortranarray(np.array(row_major_array, copy = True))

print(row_major_array.flags['C_CONTIGUOUS'])
print(col_major_array.flags['F_CONTIGUOUS'])

start = time.time()
for i in range(1000):
    row_major_sum_along_rows = np.sum(row_major_array, axis = 0)
    row_major_sum_along_columns = np.sum(row_major_array, axis = 1)
end = time.time()
row_major_elapsed = (end - start) / 1000

start = time.time()
for i in range(1000):
    col_major_sum_along_rows = np.sum(col_major_array, axis = 0)
    col_major_sum_along_columns = np.sum(col_major_array, axis = 1)
end = time.time()
col_major_elapsed = (end - start) / 1000

print(f"Row major average time: {row_major_elapsed*1000} milli seconds.")
print(f"Col major average time: {col_major_elapsed*1000} milli seconds.")

LOG:

True 
True 
Row major average time: 0.03357 milli seconds. 
Col major average time: 0.28725 milli seconds.

This time around, each array has 2 columns and 10,000 rows. The same two summations are performed. Unsurprisingly, the performance difference is approximately equal but opposite to our first example. This time around, the row major order performs better than column major due to the smaller memory distance traveled to fetch required values.

For Python applications that deal with relatively small historical data, these speed differences will not make a major difference in performance. But if you deal with sufficiently large datasets, or high volumes of data coming in real-time, these speed differences can have a huge impact. In both of the presented examples, array contiguity is solely responsible for an approximately 10x difference in speed. These are toy problems; the actual performance differences will vary from application to application. NumPy does give you the ability to specify array contiguity for a reason, though!

If there are other ways you speed up your Python code that uses NumPy, we'd love to hear about it. Join our Gitter discussion page and Slack community where we enjoy discussion of topics like this one.


r/pythontips • • Oct 08 '21

Short_Video Python Interview Questions and Answers

48 Upvotes

most asked Python Interview Questions

In this video, you will find such as basic, intermediate, and advanced Python Interview questions and their answers for freshers and experienced candidates in order to prepare for their upcoming interview.


r/pythontips • • Aug 02 '21

Data_Science 8 tricks to use S3 more effectively with Python

48 Upvotes

Leverage the power of S3 in Python by:

  1. Reading objects without downloading them

  2. Downloading files to a temporary directory

  3. Specifying content type when uploading files

  4. Retrieving only objects with a specific content-type

  5. Hosting a static HTML report

  6. Generating presigned URLs for temporary access

  7. Uploading large files with multipart upload

  8. Making use of S3 Transfer Acceleration

I've put together a "how-to" on each of these 8 methods (incl code snippets) here: https://dashbird.io/blog/aws-s3-python-tricks/


r/pythontips • • Jun 22 '21

Short_Video Amazing Desktop Widget with Python

48 Upvotes

In this tutorial I have create a digital clock demonstrating how you can use python tk to create a splash screen like widget on your desktop that would work in the background. Using this simple method you can create many such projects regarding floating widget which will be fixed in a place on desktop.
Here is the Source code:- https://pysnakeblog.blogspot.com/2021/01/amazing-widget-with-python-onscreen.html

And video for better understanding:- https://www.youtube.com/watch?v=Wnn5fjXx25o


r/pythontips • • May 18 '21

Module QLogging: Beautifully colored, quick and simple Python logging

48 Upvotes

Github

Install:

$ pip install qlogging

Example:

import qlogging

logger = qlogging.get_logger(level='debug')

logger.debug("This is debug")

logger.info("This is info")

logger.warning("This is warning")

logger.error("This is an error")

logger.critical("This is a critical")

Screenshot:

Features:

  • Based on Python logging library

  • Color logging in Terminal and CMD

  • Color logging in Jupyter Notebook and Jupyter Lab

  • Color logging in Kaggle Notebook

  • Color logging in Google Colab Notebook

  • Know which function the logger was called from

  • Know while line number the logger was called from

  • Support logging to a file

  • Simple and clean one-liner

  • Customizable

Feedback welcomed!


r/pythontips • • Jul 30 '20

Syntax Python Basics for Beginners

48 Upvotes

Hi all,

Here I am sharing Python Basics part 1 for beginners. This blog is prt of my 100DaysofMachineLearning challenge.

https://medium.com/the-innovation/python-basics-variables-data-types-and-list-59cea3dfe10f

Please share your feedback.

Thanks.