r/learnpython • u/whealton • Nov 01 '26
Been away from Python / PyCharm for a while - any ideas on this?
Everybody, let me prefix this by saying I've been away from Python for several years, but now I need to teach an introductory class. I'm encountering something very bizarre in JetBrains PyCharm. I keep thinking it's gotta be me (and it probably is), but I was wondering if any of you can pick this out?
Because I don't appear able to post a screen snip, I'll post the code.
list_2d = [["1", "Wheel Burrow", 29.00], # A 2D list, different data types (string / float)
["2", "Jack Hammer", 594.29],
["3", "Power Drill", 39.99]]
for j in range(0, len(list_2d), 1): # Iterate through our 2D list
print(f"Item Number: {list_2d[j][0]:<3}\tItem Name: {list_2d[j][1]:<15}\tItem Cost: $ {float(list_2d[j][2]):>6.2f}")
Item Number: 1 Item Name: Wheel Burrow Item Cost: $ 29.00
Item Number: 2 Item Name: Jack Hammer Item Cost: $ 594.29
Item Number: 3 Item Name: Power Drill Item Cost: $ 39.99Now, you're probably saying to yourself, "why are you casting the float to a float?" I hear you loud and clear. Here's the thing - if I don't do that, PyCharm is flagging it as "format code f not supported for str," but here's the thing - it still prints it correctly as shown above.
This was the original line and the >6.2f is what is being flagged.
print(f"Item Number: {list_2d[j][0]:<3}\tItem Name: {list_2d[j][1]:<15}\tItem Cost: $ {list_2d[j][2]:>6.2f}")I knew I had been away for a while, but geez. This is PyCharm 2026.2.3 using Python 3.14.7 under Windows 11. Am I missing anything? Note that I also go into a single dimension list but even if I comment all that code out, nothing changes. Thank you in advance for any potential ideas on where I probably goofed it.
5
u/TheCozyRuneFox Nov 01 '26
From what I can find this is because charm thinks the inner list values are either string or float. It doesn’t track type by position.
Also you shouldn’t be using lists for multiple type collections. Tuples are standard for that use. You could also use a data class.
6
u/AlexMTBDude Nov 01 '26
That's not the Pythonic way to do a for loop. For loops don't count in Python.
Something like this instead:
6
u/Pythagorean_1 Nov 01 '26
This doesn't look like you've been away from python but rather like you've never been there
2
u/fakemoose Nov 01 '26
Unrelated to your question, but what’s the point of using a list instead of a dictionary?
Is this supposed to be demonstrating list comprehension?
2
u/gdchinacat Nov 02 '26
You might want to check the spelling of "wheelbarrow" before putting this in front of students.
0
u/[deleted] Nov 01 '26
[deleted] — view deleted comment