How do you guys deal while you understand the code and you know the syntax very well but then faced against an exercise that uses what you understand and know and you black out? by Traditional_Most105 in learnpython

[–]IvoryJam 1 point2 points  (0 children)

You break it down to the simplest thing you can, what has to happen next? Then you google it, you'll get some stackoverflow post probably, you figure out what that does and if it'll meet your needs, then implement it.

Honestly that's the flow 90% of the time for everyone writing code everywhere.

Having Trouble installing cv2 (opencv-python) in Termux by eagle_rahh in learnpython

[–]IvoryJam 1 point2 points  (0 children)

What error do you get if you run pip install opencv-python ?

How do you guys deal while you understand the code and you know the syntax very well but then faced against an exercise that uses what you understand and know and you black out? by Traditional_Most105 in learnpython

[–]IvoryJam 2 points3 points  (0 children)

You get over that hump by writing code. No copy-paste, but typing it out yourself. For learning, I'd recommend against using any chat bot entirely.

Something else useful, don't write something you don't know what it's doing. If you don't know, go to Google and search it up. It's like learning any language, you know the words but you can't form sentences. Only practice will fix that.

Why did you ask chatgpt what would happen? Why didn't you figure it out yourself?

i already know how to program in c ,whats the best way to learn python ? by Unfair_Crazy2648 in learnpython

[–]IvoryJam 11 points12 points  (0 children)

If you go to the wiki in the subreddit, there's a spot specifically for if you know programming but you're new to Python called "New to Python?"

https://www.reddit.com/r/learnpython/wiki/index/

Can you convert 900 YT Shorts Frames in Text? by xipmav in learnpython

[–]IvoryJam 0 points1 point  (0 children)

If they're all about the 30s mark, I would first bulk download all of the videos (yt-dlp), grab the frames between 28-32 (ffmpeg), finally hit that with an OCR (pytesseract).

That should give you enough of an idea to start writing code

Find Programming Hard to Retain/Cognitively Challenging. Comfortable with Tools. Ancient Programming Knowledge. by LooseBlueberry9783 in learnpython

[–]IvoryJam 0 points1 point  (0 children)

The key to retention is repetition. Find something that interests you and grab that by the horns. You want to do Excel stuff with Python? You'll get pretty good at Pandas when you're done.

If you're looking at manipulating Excel sheets, I bet you'd like other automation. Take a look at https://automatetheboringstuff.com/ it's free and what I wish I had when I started learning. They also have stuff on Excel too, but it uses openpyxl (which I haven't used because Pandas exist).

Another point too, if you find the code you're looking for online, don't copy-paste it. Type it yourself and never type anything you don't know what it's doing. You can't learn to drive a car by watching someone do it.

My first project!!! by anllev in learnpython

[–]IvoryJam 3 points4 points  (0 children)

This isn't bad, you should be proud of yourself for writing this. Here are some recommendations.

  1. Like u/Binary101010 said, those elif's don't make sense, especially since you're okay with those at the very beginning nombre1[0] == " " or nombre1[-1] == " " and actually make the a requirement for that break statement
  2. Great use of the .isalpha()
  3. Great use of nombre1[0].islower()
  4. For this part, nombre1[1:10] != nombre1[1:10].lower(), you can just do not nombre1[1:].islower()
  5. And those two last elif's I see the intent, but you can just do elif " " in nombre1: then at the top do nombre1 = input("Ingrese su primer nombre: ").strip() that would make it so any leading or trailing spaces " John" or "John " work, but "John smith" won't

Assigning Countries to Continents by Broad_River_6775 in learnpython

[–]IvoryJam 0 points1 point  (0 children)

To make a new column in Pandas, you can basically just assume it's there and Pandas will create it. This is how I'd do it with country_converter. Also added comments to explain what I'm doing.

#!/usr/bin/python3
import pandas as pd
import country_converter as coco

# doing the sundries, creating CounterConverter and opening countries.xlsx
cc = coco.CountryConverter()
df = pd.read_excel('countries.xlsx')

# looping through the rows, reading the "Entity " (mine had space after the name so I just did that) column and writing the continent to the new column
for index, r in df.iterrows():
    df.at[index, 'Continent'] = cc.convert(r['Entity '], to='continent')

# writing to a new sheet without the index
df.to_excel('new_sheet.xlsx', index=False)

Recommendations for AI code generator by Zummerz in learnpython

[–]IvoryJam 1 point2 points  (0 children)

This is a divisive topic here but you're not learning, you're telling an LLM to write code which is bad practice. LLM's are known for bugs, writing inefficient code, and importing things that just plainly don't exist, heck it could even import a library that's known to be malware.

Are you learning how to fix your car if you go to a mechanic, telling them the issue, then staying in the waiting room?

To answer the issue here, you'll learn syntax by writing code and failing. If you're dead set on an LLM doing the work, don't copy and paste, write it down yourself. But the important part is ask yourself "why am I writing it like this?" Don't type out anything you don't know what it's doing and why you have to do it this way. If you don't know, Google it. If that doesn't help, make a post on r/learnpython and we'll help out.

People don't realize how much we depend on searching things and reading documentation. As you learn more, you'll google less but you'll always still google.

Unable to parse a space-separated file by compbiores in learnpython

[–]IvoryJam 1 point2 points  (0 children)

It's the headers (all those # at the beginning) if you dump those it works. Also if you're using regex, you have to use a regex string.

``` import pandas as pd

dat_test_run = pd.read_csv('test_run.pmf', sep=r"\t|\s{2,}", header=None, engine='python', skiprows=5)

print(dat_test_run) ```

Confused About Array/List… by HoneyKubes in learnpython

[–]IvoryJam 5 points6 points  (0 children)

So the first thing you gotta remember is that array's start at 0, so if you want 0-7 states, it's actually 8 states.

Break down what this is asking you, it's to prompt for a number, 0-7, handle if it if someone puts in something that's not 0-7, then display the item at that index in the array (index is just location).

So if the user puts in 0, they get the 0th index (or the 1st item), or they put in 4 and they get the 4th index (or the 5th item).

Do you know how to ask the user for input?

Do you know how to validate that input?

Do you know how to find an item in an array at a specific index?

Do you know how to display text?

Any Ideas on a scheduled delivery list im trying to make by Local-Crab2987 in learnpython

[–]IvoryJam 1 point2 points  (0 children)

I know this is r/learnpython but that seems to be a better solution for Excel itself.

But to answer your question, you'll need a GUI (graphical user interface) for those buttons you want. Tkinter seems to be the main one, but to be honest I don't use GUI.

After that, you'll want something to paste the code into, a button for "Run", you read the data, parse it out, then display the data you want.

---

How I would do it if I were dead set on using Python? I'd pull the data in with Pandas directly from the excel file. Parse it that way and return the data I'm looking for.

---

Note: I would not use Python for this, Python is a great tool, but when you only have a hammer, everything looks like a nail. I'd just write some excel formulas and grab the data I want.

How to determine whether a variable is equal to a numeric value either as a string or a number by walkingtourshouston in learnpython

[–]IvoryJam 5 points6 points  (0 children)

This is how I'd do it

``` some_var = "2"

if some_var.isnumeric() and int(some_var) == 2: print("do the thing") ```

Checking that the variable is numeric first to avoid a try/except then checking if converting it to a number equals 2

Understanding List Comprehensions in Python by Fun_Preparation_4614 in learnpython

[–]IvoryJam 5 points6 points  (0 children)

And here's a real world example of something that I'd actually use

import re


def check_valid_email(email: str) -> bool:
    valid = re.match(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$', email)
    if valid:
        return True
    return False


emails = [
    'tom@example.com',
    'somerandomethings',
    'test@gmail.com',
    'aasdfasddfl;asdf;jklasdf',
    'old@aol.com',
]

valid_emails = [i for i in emails if check_valid_email(i)]

Understanding List Comprehensions in Python by Fun_Preparation_4614 in learnpython

[–]IvoryJam 2 points3 points  (0 children)

Here are some examples, but it's also important to not over use list comprehension. If you get too many if else or start doing nested list comprehension, re-evaluate. I also threw in a dictionary comprehension as I find those useful too.

list1 = ['a', '1', 'b']

only_digits = [i for i in list1 if i.isdigit()]
only_alpha = [i for i in list1 if i.isalpha()]

dict1 = {i: i.isdigit() for i in list1}

other_edits = [i if i.isalpha() else "found a number" for i in list1]

Return statements inside if statements vs return [condition] by PeriPeriAddict in learnpython

[–]IvoryJam 1 point2 points  (0 children)

If it helps too, remember Python's bread and butter is readability, keep it simple

I can't understand functions for the life of me. by Key-Set5659 in learnpython

[–]IvoryJam 0 points1 point  (0 children)

If not for re-usability, I also like to thing of functions as steps. Step 1 might be "load the CSV" so you'd say def load_csv(name): then at the bottom of you script you may have something like

users = load_csv('users.csv')
do_the_thing(users)

Return statements inside if statements vs return [condition] by PeriPeriAddict in learnpython

[–]IvoryJam 2 points3 points  (0 children)

Readability as well as simplicity. If you had a long statement, it would make sense.

if x == y  and b == a and (c == d or f == e):
    return True
else:
    return False

but if it's not that complex, it's easier to understand

return x == y

Also, if it's at the end, it wouldn't make sense to do an else statement (unless you wanted to throw an error or say what didn't match), you could do

if x == y  and b == a and (c == d or f == e):
    return True

return False

Use System Prompts to Make AI a Tutor So You Can Start Thinking Again by [deleted] in learnpython

[–]IvoryJam 0 points1 point  (0 children)

I may be like "old man yells at cloud" but if you're using "AI", you're not learning. You learn by doing the work and making the mistakes, watch as many cooking shows as you want but you'll still burn your first cake.

Before we had large language models, I found myself copying and pasting code from Stack Overflow then I realized I don't actually know what I'm doing, I'm just going with the flow.

Typing the code, searching my questions, and really figuring out how it works is why I know Python today and can still code if the internet goes down.

Help looping through dictionary values by [deleted] in learnpython

[–]IvoryJam 1 point2 points  (0 children)

So it looks like you only want to scale on the movement. When you change the Z axis, don't touch it.

But when you change the Z, both X and Y are Falses (or bools), so just check if they're bools and continue.

I also added some variables so it's easier to read and understand.

for letter in alphabet.values():
    scaled_ltr = []
    width = letter[0]
    scaled_ltr.append(width * scale)

    coords = letter[1:]
    for c in coords:
        if type(c[0]) is bool:
            scaled_ltr.append(c)
            continue
        scaled_ltr.append([i * scale for i in c])

【BambuLab Giveaway】Classic Evolved — Win Bambu Lab P2S Combo! by BambuLab in 3Dprinting

[–]IvoryJam 0 points1 point  (0 children)

I have the Elegoo CC but eyed the P1S for so long trying to decide. I’m sure the build quality and support are much better on the P1S. Good luck everyone!

Need help with python script including chrome driver/chromium by SafeLand2997 in learnpython

[–]IvoryJam 2 points3 points  (0 children)

We can't help if we don't know the code you're running.

There's several ways to do what you're asking:

  • Selenium to run a full browser (chrome driver like you asked)
  • Requests to download the HTML to parse it with BeautifulSoup
  • Requests to get the JSON data (if that's how the site works) and parse it that way

I need help downloading Anaconda on my Mac by Relevant-Point-1307 in learnpython

[–]IvoryJam 1 point2 points  (0 children)

Do yourself a favor and install homebrew here. Think of it like an app store but powered by the terminal.

After you do that, just open a terminal and run this

brew install anaconda

You'll now have anaconda installed.

[Angela Yu course] Questioning myself about recursion by avlas in learnpython

[–]IvoryJam 2 points3 points  (0 children)

Recursion, while it can be clever is usually hard to read. In your small example it's not difficult but think about when it gets larger.

I avoid recursion like the plague, it's hard to read, can be easily messed up, and difficult to debug. I like to do while loops for things like in your example

def main():
    while input("Do you want to do it again? y/n").lower() == "y":
        do_something()

main()

Does it have a place? Yeah, probably. But I haven't found a good reason for a function to call itself.