What does this mean?
September 19, 2023 7:26 PM   Subscribe

I'm slowly teaching myself python using some of these exercises. I'm using Visual Studio and storing everything on Git Hub. That's just background...

I'm working on exercise 3 (repo here) and I actually don't have a programming question (for a change). My question is, where did this come from...

from functools import total_ordering

I didn't put it there. So I assume VS did. I've not gotten far enough that I'm importing anything from anywhere, though I have heard of the idea.

I did google like a good girl. But
1. I can't figure out how it got into my code in the first place
and
2. I'm not understanding what I'm reading about functools or how it relates that what I'm doing.

I know I can do everything in a text editor, but I like how VS helpfully tells you when you've messed something up, the ability to run the program within VS, and (now that I've figured it out) the integration with Git Hub.

PS: Please don't laugh at my code. I'm really starting from scratch here after starting the CS course on Brilliant (see my previous question on algorithms).
posted by kathrynm to Computers & Internet (8 answers total) 7 users marked this as a favorite
 
Best answer: VSCode autocomplete will do that sometimes. You type "total_", it suggests total_ordering, you accept it, realize it's wrong, and backspace to fix it, and meanwhile, the import has "helpfully" been added to the top of your file.
posted by Blue Jello Elf at 7:56 PM on September 19, 2023 [10 favorites]


Best answer: Well, I can't say with 100% certainty how that import got into your code. Some code editors will autocomplete certain common "phrases" in programming languages, and it's possible that you accidentally activated an autocomplete feature that pasted it in. I've definitely done similar things with at least two editors in my time (not a regular VSCode user, admittedly).

What I can say is that you can safely remove it, because it's not necessary or related to the exercises you're working on. The tools in functools are for automating some relatively advanced techniques, where you're creating custom data types and building new functions by operating on existing ones. That's stuff you won't have to do until later in your Python learning.
posted by egregious theorem at 7:58 PM on September 19, 2023


Best answer: Yeah, modern editors let our typos take us further and faster than ever before. As has been said you can safely remove the line.
posted by Tell Me No Lies at 8:09 PM on September 19, 2023 [5 favorites]


Best answer: Agree with the other answers but mainly posting to say everyone is a beginner at first, and if anyone laughed at your code they'd be a horrible person who isn't worthy of your time. You're doing great!
posted by underclocked at 11:21 PM on September 19, 2023 [10 favorites]


Best answer: Just to add, you can probably disable this behaviour somewhere in VSCode settings. I don't code in Python so don't have any of the language extensions installed, but if you search in settings for some combination of "python / auto / import" something should show up.

Also, if you keep the feature turned on it's good to get into the habit of using ctrl + z to undo when possible, which (vs. backspacing) will step you back through the sequence of what was modified change by change (making it easier to see when something you didn't expect was added) and will remove auto-import lines as well.
posted by protorp at 12:24 AM on September 20, 2023 [1 favorite]


Response by poster: Thanks all.

Must have been an autocomplete thing because I have a variable called total_value.

Also, thanks underclocked
posted by kathrynm at 7:05 AM on September 20, 2023 [1 favorite]


Good luck on your journey!
posted by lostburner at 2:46 PM on September 20, 2023


Response by poster: Just in case anyone was curious, I finished this silly little program and I'm on to my next challenge.
posted by kathrynm at 6:06 PM on September 22, 2023


« Older Falling in love one episode at a time   |   How normal is it to lose academic skills after... Newer »

You are not logged in, either login or create an account to post comments