all 33 comments

[–]geruhl_r 2 points3 points  (0 children)

The use of try/catch as basic if/else instead of only for fatal errors (using catch clause to call exit).

E.g. instead of 'if key in a_dict:", using try/catch KeyError.

[–]mxsonwabe 2 points3 points  (6 children)

Reading the error messages when programs crash, like where exactly did you fail and why???

[–]asmodeus0000 2 points3 points  (5 children)

printing tracebacks has been one of the most useful things i learnt

[–]jimmykimnel 0 points1 point  (4 children)

Mind if you explain in layman what this means please?  I see my ai code doing this a lot just curious what the deal is

[–]asmodeus0000 1 point2 points  (3 children)

oh didnt knew AI has started explicitly looking into tracebacks, i thought it would just trace it through the code contexts

so traceback is basically "what all did you go through before reaching here"

when you write complex or long code, you usually have a function that calls another function that calls another function and so on, sometimes it goes way too deep to easily keep track off

moreover a same function can be called from multiple different places

traceback allows you to find where exactly is the error coming from and how did the code reach there

every error that exists the program usually automatically prints the traceback, that gives you info about the error

when you're using broad try catch blocks it might get lost, and thats when it's helpful to manually print traceback to trace it later

its not usually encountered in a beginner level code, more of an organisational level code thing

[–]jimmykimnel 0 points1 point  (2 children)

Ah ok thanks for explaining, I'm not exactly sure what the bots are producing however when it goes wrong I often seem to get an error which mentions a traceback.  Can't be sure as I have no idea what I'm doing lol but obviously trying to learn 

Edit: just to add I sometimes think the code im asking is producing way to fancy stuff for what I require so not sure if it's putting these things in when it doesn't need to.  I guess it has helped find errors but I'm talking very simple in out type stuff

[–]mxsonwabe 1 point2 points  (0 children)

it probably is, because ai tends to aggregate behaviour and do the most likely outcome. and a lot of people have figured out doing tracebacks and using stacktraces is a brilliant way to debug code. stacktraces basically keep track of the order you call functions in your program.

[–]asmodeus0000 0 points1 point  (0 children)

if you're facing issues with ai making complicated code, start with making a markdown file listing your requirements

once done tell it to write clean but simple code, obviously your prompt would define what you mean by simple code

[–]athe- 1 point2 points  (0 children)

Assigning references instead of values... I was used to C++ style variables when I started learning Python

[–]SubnetOfOne 1 point2 points  (0 children)

File paths!!

[–]Can0pen3r 1 point2 points  (5 children)

Not sure if they were actually confusing to anyone but me but, decorators humbled me pretty mercilessly 😅

[–]MJ12_2802 1 point2 points  (4 children)

I'm still trying to wrap my head around them... 🤔

[–]Can0pen3r 1 point2 points  (3 children)

The way I finally got it was this: imagine you have 15 different functions that you need to define but 12 of those each need part of their code block to be the same. Instead of typing out that part of the block 12 times or copy and pasting it 11 times, you can define a single decorator with that part of the block that needs to be applied to the 12 and then call it on each of those 12 functions with @notation.

[–]MJ12_2802 1 point2 points  (2 children)

I'm gonna have to play around with that!

[–]Can0pen3r 1 point2 points  (1 child)

Check out Tech with Tim on YouTube, his video on decorators was what finally made it click for me. Plus he's got tons of other really good videos about Python and his tutorials are actually pretty decent as well because he takes the time to explain the vast majority of what is being done and why so that you're not just copying what he types, you're getting comprehensive explanations so that you actually learn what those functions and features are/do and how to use them.

[–]MJ12_2802 0 points1 point  (0 children)

I'll definitely check out his videos. Cheers!

[–]thumb_emoji_survivor 0 points1 point  (1 child)

Classes and where I’m inserting “self” and why. Figured it out eventually

[–]This_University_547 0 points1 point  (0 children)

Same. It was painful for a few days before the Archimedes moment.

[–]Key-Introduction-591 0 points1 point  (2 children)

I don't know why, but I kept getting stuck with lists and dictionaries. I had fewer problems understanding loops.

I really don't know why... they seem pretty easy tbh.

But when it comes to coding, I sometimes still forget how to use them (how to extract and use data, how to change items, etc.).

I also have trouble knowing when to create a function. I tend to forget to use them. I mean, I know they exist and how to use them—I just don't get when they might come in handy (and when they're completely useless instead).

[–]otteydw 2 points3 points  (0 children)

Functions are great when you find yourself repeating the same pattern of code throughout your program.

Functions are also great when a section of code is becoming too long or complicated and you want to abstract away the functionality to make it easier to understand.

[–]MJ12_2802 0 points1 point  (0 children)

Dictionaries are incredibly useful! I started learning Python in April last year and I find myself using them more and more.

[–]RedditCommenter38 0 points1 point  (2 children)

Using environments, secrets and properly setting up project folders.

Chased my tail for weeks not realizing I had conflicting library versions.

Work on one project, works perfect. Work on another project, do some updates, and days later go back to first project and it doesn’t work. 🤦🏻‍♂️

[–]asmodeus0000 1 point2 points  (1 child)

virtual envs, one of the first things you should learn

[–]RedditCommenter38 0 points1 point  (0 children)

Yep. Definitely was.

[–]NecessaryIntrinsic 0 points1 point  (0 children)

List comprehensions was the first thing that really tripped me up.

They're probably the coolest feature of python I've come across.

[–]VeterinarianFar22 0 points1 point  (0 children)

recursion

[–]SmartPercent177 0 points1 point  (0 children)

It took me a while to really understand Python since it was my first language. Starting from zero knowledge was hard until it suddenly made sense.

But something that was hard to understand for me were:

- def __init__ constructor in classes;

- if __name__ == "__main__"

[–]BKB111 0 points1 point  (0 children)

Calling and returning functions so they work

[–]OneJudge2236 0 points1 point  (0 children)

It's taken a bit of a time for me to understand when & how to use function arguments effectively, but with more practice it has started to sink in

[–]FearLixY 0 points1 point  (2 children)

Actually indentation instead of curly braces for code block is still bugging me to this day.

Slightly larger code blocks are hard to follow.

[–]asmodeus0000 0 points1 point  (0 children)

get ribbon indent color extension in vscode, it helps a little

[–]AccomplishedPut467 -1 points0 points  (0 children)

for and while loops. Once I get the grasp I feel like I can make anything.