r/learningpython • • Jan 29 '25

Question regarding the OSINT cert offered by McMaster University in Canada Question

1 Upvotes

Hello,

Has anyone here taken the OSINT cert offered by McMaster University, which teaches people who to use python for OSINT? If so, would you recommend it? Thank you.


r/learningpython • • Jan 22 '25

Looking to practice loops

1 Upvotes

Hello,

Do any of you guys know of any platforms where you can practice writing loops with the help an AI instructor? Thank you for your time.


r/learningpython • • Jan 20 '25

Difficulty Understanding The Disconnect

1 Upvotes

I have a tray application I'm building in PyQT6. I'm trying to make a popup window that scales based on screen resolution size and the contents within the popup but whenever I try it on a resolution not my own, it's not scaling at all. The text is getting cut off and it feels either too cramped or too spaced out. I can give some code snippets if needed but I'm wondering if someone might have a way to do this already that I can reference to verify.


r/learningpython • • Jun 05 '24

If statements

1 Upvotes

I've always had trouble reading written problems so that I can break it down for math equations let alone coding. Do anyone have any words of advice to help me with the break down of written problems?


r/learningpython • • May 27 '24

Please help!!!! Python project for final grade. While loops being weird

1 Upvotes

Hi everyone! I'm coding a project for a final grade in my intro to computer science class in school. My code is going well, except that I have a while loop within a while loop that is acting funky. When the inner loop finishes, it restarts from what is at the start of the outer while loop. I don't want it to do this. (Also sorry of this doesn't make sense, I'm very tired.) Any help is greatly appreciated! My groupmate and I have been stuck on this for hours. Also, this is my first reddit post ever so sorry if I'm posting in the wrong spot.

I'm going to paste the code down below. The game is a choose-your-own-adventure game.

sanity = 50

hostility = 50

kill = 0

if enter == "window":
while kill == 0:

print("You search for a window to break into. You go to the backyard and up the porch, and you see a window. You smash it, making a loud sound. You climb through the window, and you are now in the kitchen.")

print("The sound was loud, but sudden. You hope whoever is in here didn't notice.")

hostility += 10

sanity -= 2

print("You look around, the light above the microwave is dim enough for you to see your surroundings.")

print("You realize that in your haste to get to the scene, you hadn't actually grabbed your gun from your car.")

print("You search the kitchen. It's a nice and polished little room, with plenty of tools lying around. You notice several knives in a knife holder, a frying pan in the sink, and a glass on the kitchen table.")

KTR = input("Do you grab one of the items?")

if KTR == "yes":

KT = input("Options: 'knife' , 'pan' , 'glass'")

if KT == "knife":

print("You walk over to the knife block and carefully pull the biggest knife out. It is a little dull, but it works.")

print("You continue on, going through the dining room. A clock quietly ticks on the wall. It is the only sound you can hear.")

elif KT == "pan":

print("You walk over to the sink and grab the frying pan. As you pull it out, you accidentally hit another item in the sink, making a sound.")

hostility += 5

sanity -= 2

print("You continue on, going through the dining room. A clock quietly ticks on the wall. It is the only sound you can hear.")

elif KT == "glass":

print("You grab the glass off of the table and pour the little bit of water inside into the plant next to the window.")

print("You continue on, going through the dining room. A clock quietly ticks on the wall. It is the only sound you can hear.")

else:

KT = "none"

print("You continue on, going through the dining room. A clock quietly ticks on the wall. It is the only sound you can hear.")

print("You peek in the living room, and you notice a large safe inside.")

safe = input("Do you want to try to open the safe?")

if safe == "yes":

sanity -= 2

print("You recognize this type of safe. It only requires a two-digit combination, but you only have 3 tries to open it before it fully locks down. Then, a special key is required.")

guess = 0

tries = 0

combo = 37

while tries < 3 and guess != combo:

guess = int(input("Guess the combination."))

tries += 1

if guess == combo:

print("You guessed the combination correctly! You opened the safe, and inside was a shotgun and a pack of bullets. You grabbed the gun.")

else:

print("Too bad, you didn't get the combo.")

else:

print("You decide not to open the safe.")


r/learningpython • • Apr 30 '24

How to extract only part of a table from a PDF file using pdfplumber?

1 Upvotes

Hi,

I am trying to use pdfplumber to extract ONLY certain data from a table in a PDF file to a CSV file. This is the picture of the table I am looking at.

As of now, I am at the point where the table is written in the excel file. Here is the code I have so far:

# Define extraction regions for each table (adjust coordinates as needed)
regions = [
(10, 100, 600, 260),
]
# Region for Table 1
# Add more regions for additional tables if needed

# Define the desired headers

# Specify the directory and filename for saving the CSV file
output_directory = "C:/Users/myname/Downloads"
output_filename = "clients_info.csv"
output_path = os.path.join(output_directory, output_filename)

with pdfplumber.open("C:/Users/myname/Downloads/clients.pdf") as pdf:
for region_index, region in enumerate(regions):
x1, y1, x2, y2 = region
tables_data = []  # Store data for all tables in this region

page = pdf.pages[0]  # Extracting tables from the first page
table = page.within_bbox((x1, y1, x2, y2)).extract_table()

# Extract header row and filter out None values
header_row = [cell for cell in table[0] if cell is not None]

# Extract data rows and remove None values
for row in table[1:]:
filtered_row = [cell if cell is not None else "" for cell in row]
tables_data.append(filtered_row)

# Write the data for this region to a CSV file
with open(output_path, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(header_row)  # Write the filtered header row to the CSV file
for row in tables_data:
writer.writerow(row)  # Write the data rows to the CSV file

However, I only wanna write the headers that are highlighted in red in the first row of excel and the corresponding data (white cells that are in red) in the second row. How should I improve it to print only the ones that are highlighted in red? 

Thank you so much for your help.


r/learningpython • • Dec 07 '23

getting started with MicroPython - do we need the special Board or can we use others too ?

1 Upvotes

getting started with MicroPython - do we need the special Board or can we use others too

  • do we benefit from using the pyboard (and if so why)

  • can we use Raspi-Pico or others

  • or the ESP32


r/learningpython • • Sep 19 '23

Does anyone wants to "collaborate"?

1 Upvotes

Ive been programming in Python for several years, but as far as I can tell, I havent even come close to a Junior level, despite having experience in commercial projects and having a job where I currently work. However, Ive never worked in a team and I have no idea what its like. The people Ive met are either too novice or too advanced so I had no chance to work with someone. If you have an idea or just want to try working in a team, let me know, I would be very happy to try it.


r/learningpython • • Jul 04 '23

How is this invalid syntax?

1 Upvotes

The directions are "Using a conditional expression, write a statement that increments num_users if update_direction is 3, otherwise decrements num_users."

Sample output with inputs: 8 3New value is: 9

I'm getting this error and I don't understand why?

I'm just trying to decrement. How is ' -= ' invalid syntax?

Thanks!


r/learningpython • • Jun 27 '23

Does anybody have any experience with learning Python on app.dataquest.io?

1 Upvotes

It uses Jupyter and I haven't gone for the paid subscription yet because the free version doesn't seem to run the code correctly. Wonder if it's just me or a typical experience.


r/learningpython • • Jun 26 '23

BERT-Based Classification Model for Google Local Listings

Thumbnail
huggingface.co
1 Upvotes

r/learningpython • • Mar 07 '23

Can't find what's wrong with my code

Thumbnail
gallery
1 Upvotes

r/learningpython • • Feb 20 '23

plot transfer function

1 Upvotes

Hello Guys,
I get this system with sympy library, but now I would like to plot the transfer function. How can I plot the bode diagram of this system?
How can I get only the numerator and denominator in two different variables to find the poles and zeros?


r/learningpython • • Feb 13 '23

Pandas: Integrating with NumPy, Matplotlib, and Scikit-learn

Thumbnail technicbate.blogspot.com
1 Upvotes

r/learningpython • • Jan 30 '23

Why is only the last file saving in a loop? The other files are processing inn the loop and are creating temporary files but none save

1 Upvotes

Hello,

I am working on an ArcGIS code where I am looping through multiple images in a folder. I see the files are looping in the project folder (when each image is processed a temporary file comes up but they disappear after the process is complete) but only the last image in the folder saves.I have the save function written in the code but it doesn't actually save. Could someone please help me with what I am missing? My code is below:

#imports

import arcpy

import os

import glob

from arcpy import env

from arcpy.sa import *

arcpy.CheckOutExtension("Spatial")

#Environments

env.workspace = r"Folder_pathway"

arcpy.env.extent = r"Shapefile_Pathway"

indef_file = "Classification_Pathway"

#Variable

inRasters = glob.glob(r"File_pathway\\*.tif")

inMaskData = "Quads"

extraction_area = "OUTSIDE"

analysis_extent = "Quads"

#Loop

for inRaster in inRasters:

outExtractByMask = ExtractByMask(inRaster, inMaskData)

classifiedraster = ClassifyRaster(outExtractByMask, indef_file)

classifiedraster.save = (r"Folder_pathway")

newname = inRaster + "CF"

arcpy.management.Rename(classifiedraster,newname)

...I want to add more after this part of the loop but I will need to do a second loop with the *.crf files, but I can only get the one to save.

The rename creates one folder with the correct name in the project file_pathway, but only the last one.


r/learningpython • • Jan 18 '23

Use Python to Scrape Republic Day Sale | Free Masterclass

Thumbnail
eventbrite.com
1 Upvotes

r/learningpython • • Jan 17 '23

Analyzing Loan Application Data Using Python | Free Masterclass

Thumbnail
eventbrite.com
1 Upvotes

r/learningpython • • Jan 03 '23

Help me with my python code for my discord server

1 Upvotes

i want to create a discord server that let users earn "diamonds" when they type !work. i tried this code in pycharm but it displayed some errors. by the way, im a newbie in coding and this code is generated through chatgpt. so im not an expert here because my line of work is very different from the world of coding.

import discord import random

client = discord.Client()

@client.event async def on_message(message): if message.content == "!work": num_diamonds = random.randint(200, 301) # Generate a random number of diamonds between 200 and 300 for i in range(num_diamonds): # Add the specified number of diamonds to the message await message.add_reaction("💎")

client.run("YOUR_BOT_TOKEN_HERE")

Can you please point out the mistakes in this code. thanks


r/learningpython • • Nov 22 '22

Structuring Programs

1 Upvotes

I come from plc programming. I know it’s much different then python. I’m not worried about the programming portion but more of the structuring an entire application. What is this called that way I can try and research more about it. However without me knowing what to look for I’m kind of at a dead end. Thank you


r/learningpython • • Nov 10 '22

help with this

1 Upvotes

hey I'm trying to create this app and I wanna combine the 1 with 2

(1)

# draw ideas random

import random

object1 = " a coffe mug "," base ball "," airpods "," airpods case "," air macbook ","ladle"," plush unicorn "," seat belt "," seat belt "," wings ","empty jar"," tiger ", " small lion "," sock "," beard ","cup"," mop "," hammer "," butter knife "," ath vader "," loki "," thor "," soda can "," mickey mouse "," batman "," guitar "," katana "," long sword "," pokemon card "," sun "," robot "," black hole "," farmer "," bed "," doll "," mushroom "," deodorant "," cookie tin "," thermometer "," pencil "," bell "," sketch pad "," power "," black magic"," rat "," skunk "," meerkat "," fish "," frog "," gunea pig "," ground hog "," cat "," camel"," hedgehog "," eagle owl "," owl "," okapi ","cookie" "puppy "," grizzly "," bear "," orangutan "," jaguar "," argali "," marten "," ocelot "

object1 = " a coffe mug "," base ball "," an airpods "," an airpods case "," an air macbook "," ladle "," plush unicorn "," seat belt "," wings "," empty jar "," tiger "," big lion "," sock "," beard "," cup "," mop "," hammer "," butter knife "," dath vader ","loki"," thor "," soda can "," mickey mouse "," batman "," guitar "," katana" ," long sword "," pokemon card "," sun "," robot "," black hole "," farmer "," bed "," doll "," mushroom "," deodorant "," cookie tin "," thermometer "," pencil "," bell "," sketch pad "," black magic "," photo album "," bow tie "," chenille stick "," ball of yarn "," toy car "," sand paper "," bag "," floor "," washcloth "," spectacles "," plush dinosaur "," flag "," crowbar "," hair ribbon "," bow "," pinecone "," bracelet "," extension cord "
part = " with a "," in a "," inside ","on a "," hybrid with ","a mix between"
theme = " horror "," weird "," dramatic "," goffy "," creepy "," strange "," Fantasy "," anything "
style = " cartoonish ","1980s cartoonish "," relistic "," Photorealism "," Figure drawing "," Perspective drawing "," Gesture drawing "," Pointillism "," Scientific illustrations "," Scratchboard drawing "," Silhouette drawing "," Sketch drawing ",
string = object1
leanth = 1
string2  = object1
leanth2 = 1
string3  = part
leanth3 = 1
string4  = theme
leanth4 = 1
string5  = style
leanth5 = 1
idea = "".join(random. sample(string ,leanth))
idea2 = "".join(random. sample(string2 ,leanth2))
sss = "".join(random. sample(string3 ,leanth3))
theme = "".join(random. sample(string4 ,leanth4))
style = "".join(random. sample(string5 ,leanth5))

print("drawing idea is "+ idea + sss + idea2 + " and the theme is " + theme + " and the syle of drwing is " +style)
print("")
print("")
print("")
print("this program was made by vinicius :)")

(2)

import tkinter as tk
from tkinter import ttk
class App():
def __init__(self):
self.root = tk.Tk()
self.root.geometry('900x900')
self.root.title('random drawing ideas by vinicius')
self.mainframe = tk.Frame(self.root,  background='white')
self.mainframe.pack(fill='both', expand=True)
self.text = ttk.Label(self.mainframe, text=' click the button for random drawing idea', background='white', font=("Brass Mono", 30))
self.text.grid(row=0, column=0)
self.set_text_field = ttk.Entry(self.mainframe)
        set_textbutton = ttk.button(self.mainframe,)
self.root.mainloop()
return
if __name__ == '__main__':
App()


r/learningpython • • Oct 30 '22

Any idea why "if x in text" isn't finding it in the file?

1 Upvotes

r/learningpython • • Oct 19 '22

Mining Twitter data with Python

Thumbnail
gallery
1 Upvotes

r/learningpython • • Oct 14 '22

Django Naming Files system issues

Thumbnail self.django
1 Upvotes

r/learningpython • • Oct 13 '22

Find a list of words in a document

1 Upvotes

I assume this is an easy solution but I am still a noob with python.... I am trying to find a list of words within a document so it returns me the line they are in. I have been able to search a single word but I am unable to get my code to search for each instance in a list. The code below is as far as I get but it still seems to be only giving me the first word from the list. can you guys help?!

my document is: DOG2

The words are dog and cat.

if I can get real fancy, return the word with the line it resides in.

file = open('DOG2.txt', 'r')
word = ['Yellow','cat']
s = " "
count=1
for p in word:
    while(s):
      s = file.readline()
      L = s.split()
      if p in L:
          print("Line Number:",file.name,p,count,":",s)

      count+=1

Thanks for any help


r/learningpython • • Sep 13 '22

purpose of idle + how to activate run option on idle?

1 Upvotes

I'm a newbie to python and experimenting with various IDEs. I have a few questions regarding IDLE:

People say it's helpful to use IDLE as a supporting editor to VS code: why is this?

And how do I active the run option on IDLE? As can be seen in the attached pic, it seems the run option is activated simply by pressing a few enters. I'm working on mac os, and it seems fn + f5 does not work either.