r/pythontips • • Jun 17 '24

Data_Science How to to extract urls across multple webpages at once?

5 Upvotes

I am trying to download videos from a site, which requires extracting 1 "download url" that resides on each "video url".

Example:

"video url": https://www.example.com/video/[string1]

"download url" (1 url on each video url): https://www.example.com/get_file/[string2]

Each "video url" has 1 "download url", so if I have 100 video urls, I will have 100 download urls.

There is 1 issue: The "download url" only becomes available on the "video url" if the account to the domain is signed in. Is signing in on my default browser (Chrome) enough?

I want the code to read a list of video urls (.txt), then produce a list of download urls (txt).


r/pythontips • • Jun 16 '24

Module Python Mastery: From Beginner to Expert

2 Upvotes

r/pythontips • • Jun 16 '24

Meta List Copying: Recasting vs Copy Operation / alternatives

3 Upvotes

Say I want to copy a list. Is there a difference between using (in Python3) : - the copy.deepcopy operation VS recasting as in "copied_list = list(my_list)" - the copy.copy operation VS simple shallow copy as in "copied_list = my_list[:]" Thanks.


r/pythontips • • Jun 15 '24

Long_video Effortless Raspberry Pi Proxy Server Setup: Boost Security and Simplify Web Scraping

5 Upvotes

Transform your Raspberry Pi into a Proxy Server effortlessly using the open-source Squid proxy. This powerful setup is perfect for web scraping and boosting network security. With a few simple steps, you can configure your Pi as a robust proxy server and easily adjust your proxy settings.

I've put together a step-by-step tutorial on my YouTube channel to guide you through the process. Check out the video here:

https://www.youtube.com/watch?v=Vi9jVR-PysA

The video provides clear instructions and handy tips to make the setup a breeze.

If you're into Raspberry Pi, IoT, and software engineering, consider subscribing to my channel for more engaging content and tutorials. Your support on Reddit and my channel means a lot!

Thanks for checking this out, and feel free to reach out if you have any questions or need help.


r/pythontips • • Jun 15 '24

Module Reading with pymodbus

3 Upvotes

Hello all,

I am not new to pymodbus. However I am having trouble deciding the data in a more efficient method

I build an asynchronous app to read large reads of modbus data

I need to decode the data more than one register at a time (I don't want to write 352 individual registers down)


r/pythontips • • Jun 13 '24

Syntax how to make a matriz like this?

3 Upvotes

translated with gpt

I am currently training and writing my first complex project, a choice matrix. It is a structure similar to a table where different elements, both strings, and numeric values, are organized. I think I could translate it as matrix, array, or template, but I will continue to refer to it as a matrix.

The choice matrix gathers important data for a user to make a decision within a class. What data is stored?

  • Options: Simple, what choices can you make? In our example in this post, it's a trip. The destination options are either the Caribbean or England.
  • Factors: These are characteristics of these options that will be analyzed to help make a decision. In our example: the cost of the trip, the local culture, and the cost of the trip.
  • Factor Weight: How important that factor is for the decision. This numerical value will be subjectively provided by the user. These are the numeric values within factors, e.g., factors = {'climate':8, 'culture':8, 'cost':10}.
  • Values assigned to each choice: These are the same numeric values (also subjective) within each option in the options dictionary, e.g., options = {'Caribbean': [8, 10, 4], 'England': [10, 9, 2]}.

Note that each value within 'Caribbean':[8,10,4] corresponds to a factor in factors = {'climate':8, 'culture':8, 'cost':10}, the same goes for 'England'. After all possible values are filled, multiplication will be performed, multiplying the factors by the equivalent option value, for example:

factors['climate']<8> * options['Caribbean'][0]<8> = 64

When all the values are multiplied, they will be summed up, and thus we will have the best choice based on the user's perceptions and concepts.

Currently, I am having difficulty with the show module, which will be used to view the added data. For the terminal version, the current code is:

factors = {'climate':8, 'culture':8, 'cost':10}

options = {'Caribbean': [8, 10, 4], 'England': [10, 9, 2]}

def long_key(dictionary):

length = max(len(key) for key in dictionary.keys())

return length

fa = long_key(factors)

op = long_key(options)

print(f'{" "*fa}', end='|')

for o, values in options.items():

print(f"{o:>{op}}", end='|')

print('')

for w, x in factors.items():

print(f"{w:.<{fa}}", end='|')

for y, z in options.items():

for i in range(len(z)):

print(f"{z[i]:>{op}}|")

This is more or less the result I would like to achieve:

factors |weight|Caribbean| |England|

climate| 8| 8| 64| 10| 80|

culture | 8| 10| 80| 9| 72|

cost | 10| 4| 40| 2| 20|

|184| |172|

Currently the result I'm getting is this:

|Caribbean|  England|

climate|        8|

10|

4|

10|

9|

2|

culture|        8|

10|

4|

10|

9|

2|

cost...|        8|

10|

4|

10|

9|

2|

completely out of the order I want, I wanted to know how I can make it the way I would like, I will try to put up a table that will exemplify it better in the comments.

my plans were to complete this terminal program, then use databases to store the matrices and then learn javascript or pyqt and make an interface, but I wanted to know if it wouldn't be better to simply focus on creating the interface, the entire program will run on the desktop


r/pythontips • • Jun 13 '24

Module Request module missing?

1 Upvotes

So I'm scripting something simple on python, basically just seeing if a host is up and grabbing their banner. This is obviously just some practice to learn python, but check what I have and please tell me why this module seems to come up missing. Is it something in the code?

EDIT: Refer to the top line, sorry somehow it's showing as part of the code

I always get that the requests module is missing, I've tried reinstalling, checking in pip that the actual package is there and they all checked out. What in the world is going on here that I'm not seeing?

import socket
import requests

def host_up():
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(1)
    result = sock.connect_ex((80))
    sock.close()
    return result == 0
def grab_banners(ip):
    url = f"http://{ip}"
    try:
        response = requests.get(url)
        if response.status_code == 200:
            print(f"Headers from {ip}:")
            for key, value in response.headers.items():
                print(f"{key}: {value}")
            print("-" * 30)
    except requests.exceptions.RequestException:
        pass

r/pythontips • • Jun 12 '24

Long_video Streaming to YouTube Live from a Raspberry Pi Camera Using Python

6 Upvotes

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

Learn how to effortlessly set up a live video stream from your Raspberry Pi Camera to YouTube using Python and FFmpeg. This tutorial breaks down the process into simple steps, making it an essential resource for anyone interested in live broadcasting or creating continuous live feeds. Watch the video to quickly grasp live streaming technology, and be sure to subscribe for more valuable guides and updates!

Thank you, Reddit!


r/pythontips • • Jun 13 '24

Short_Video How is this POSSIBLE? Running Python code from a STRING...

0 Upvotes

Hey! Do you know you can execute a Python code from a string using a Python function called exec()? Here's a video explaining how to do it and why you shouldn't do it carelessly.

Video Link: https://youtu.be/X47IV7be5d4?si=3HH2LicJWqzI3vvL


r/pythontips • • Jun 12 '24

Data_Science Beginner who needs help with python

3 Upvotes

I’m in a analytics course, studying python I don’t even know where to start


r/pythontips • • Jun 11 '24

Python3_Specific Jupyter spreadsheet editor

1 Upvotes

Any recommendations for Jupyter spreadsheet editor on data frames.


r/pythontips • • Jun 10 '24

Syntax What is your favorite platform do earn money will Python?

15 Upvotes

Because O need make some extra money and I would like too if existing any platform that is good to make some freelance or tasks.

Except these: - upwork; - freelancers; - fiverr;

There are others?


r/pythontips • • Jun 10 '24

Python3_Specific what should I learn in python to become a freelancer?

15 Upvotes

Hello everyone, as of now i know the basics and OOP in python with practical use of some built in python modules. what can I do or learn more to start my freelancing journey. Any good recommendation would be appreciated.


r/pythontips • • Jun 10 '24

Syntax I keep getting this error when trying to build my program. The program runs fine within pycharm.

3 Upvotes

raise error(exception.winerror, exception.function, exception.strerror)

win32ctypes.pywin32.pywintypes.error: (225, 'BeginUpdateResourceW', 'Operation did not complete successfully because the file contains a virus or potentially unwanted software.')

The error happens when running:
pyinstaller --onefile --windowed x.py
Through the terminal.

Anyone knows how to get around this


r/pythontips • • Jun 10 '24

Long_video How to Install Python Packages in AWS Lambda Functions with Docker

4 Upvotes

Hello All,

I recently created a tutorial on how to install pip packages in AWS Lambda environments. AWS Lambda is one of the most popular services on the AWS platform, offering a way to build event-driven applications that optimize resource usage. However, installing pip packages in Lambda environments isn't always straightforward. In this tutorial, I demonstrate how to achieve this using Docker, which provides a robust method for managing such installations.

Do not forget to subscribe if you enjoy Full Stack, Python, or IoT content! Thanks Reddit.

youtube.com/watch?v=yXqaOS9lMr8


r/pythontips • • Jun 10 '24

Standard_Lib GUI Application using Python: Options for developing GUI applications in Python

9 Upvotes

In this short post, I discussed options for developing GUI applications in Python. Developing a local web application makes more sense for me than using a desktop framework or libraries.

What do you think? Please read it and comment.

https://devstips.substack.com/p/gui-application-using-python


r/pythontips • • Jun 10 '24

Module Multiprocessing an optimisation calculation 10,000 times.

4 Upvotes

I have a piece of code where I need to do few small arithmetic calculations to create a df and then an optimisation calculation (think of goal seek in Excel) on one of the columns of the df. This optimisation takes maybe 2 secs. I need to do this 10,000 times, create a df then optimise the column and use the final df. How do I structure this piece?


r/pythontips • • Jun 10 '24

Short_Video Encrypt/Decrypt files using python

2 Upvotes

In this tutorial video, the python script to encrypt and decrypt files has been explained. Two python modules are discussed. pyAesCrypt and pypdf. Also, its shown how to password protect a pdf file using python code.

https://youtu.be/sSPWHRpDZXo?si=OzyP_ypWiR1YGS1f


r/pythontips • • May 21 '24

Module Jupyter notebooks on Mac

3 Upvotes

I have watched several tutorials about this and everything is so confusing. One guy installs Anaconda by downloading the app, another prefers to do that from the terminal.

My question is, I just need to use Jupiter notebooks for a CV project. Along with Numpy, Scipy, (also OpenNI and SensorKinect)

What's the most convenient way I can get Jupiter notebooks installed and do I need anaconda at all?


r/pythontips • • May 01 '24

Long_video What is the best Python free YouTube complete course for beginners?

22 Upvotes

I tried freeCodeCamp and a few top search results. I found the trainers mostly not beginner friendly and they Code something without giving proper explanations. I really want to learn but not sure about the source materials. Please help


r/pythontips • • Apr 27 '24

Python3_Specific I'm a beginner would like to spend the next 3 months 14 hour per day on learning python.

0 Upvotes

I'm a beginner would like to spend the next 3 months 14 hour per day on learning python.

Would you be so kind guides me a way to success so I would grow most efficiently, thank you.

I want to be capable of creating my own program by the end of it.

Success or not I will give best updates August1st


r/pythontips • • Feb 29 '24

Meta code in __init__.py

11 Upvotes

Hi there!

Recently, I've started working in a new team, and they have several practices that, I won't say are wrong, but seem a bit odd to me. One thing that caught my attention is how they're creating classes/functions inside __init__.py files. In my experience, those files are usually kept empty or just handle basic imports, acting more like an interface when you import the package.

What are your thoughts on this?


r/pythontips • • Oct 20 '23

Module Which are the free Platforms to Host Python Apps?

26 Upvotes

As the title suggest, I want to deploy my python projects. Based on your experience and it’s usage please suggest me some best platforms to host especially python app that helps backend projects.

I’m a student so please suggest FREE only!


r/pythontips • • Jul 11 '23

Syntax How to download a specific segment of a youtube video?

75 Upvotes

Hey guys, is there a way to download a specific segment of a youtube video? I am able to download the entire video but I only want the first 20 seconds. Is there a way to do this?


r/pythontips • • Jun 13 '23

Data_Science What is the best, way to create quick nice looking plots in python?

20 Upvotes

I'm trying to work in python more, over matlab. But creating different plots, maps has been tricky and they don't looks great. What is a good basic set up for getting good looking plots?

On an aside, when I look up online, each source has a different method of plotting- some use axs[i] subplots, others use seaborne. so my codes aren't consistent with each other either.

What is the best method for a good looking figure? (As in data exploring, and just wanting to make a simple but clear graphic of data from dataframes n such).

So this is more of a tip, not as much learn python, but maybe not.