Python Forum
Variable for the value element in the index function??
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable for the value element in the index function??
#4
Hey, thank you both!

The second message made me take a closer look at the output, and then try a different input that showed the source of my issue was not what I thought at first. Earlier in the code, I tried to use a replace(), to remove spaces from a text string, and since there were no errors from that line, I had thought that the process had worked, but it must not have. A closer look at the output revealed that although I thought the print had worked, it only worked until it hit one of the spaces in the string (that were not removed). The early characters did print out, as I had noticed, but the error code wasn't because the index command didn't work with the variable, but because it had actually been fed the first space in the text string, and therefore failed to find that character in the list of alpha characters. I'll need to revisit the attempt to remove spaces from the string. The problem (which didn't generate an error immediately) was from this line:

lower_msg.replace(" ", "")

although it didn't reproduce correctly here with copy/paste,

in the compiler it actually looks like:

lower_msg.replace(__old:" ", __new"")

Since it added the other part itself, and it didn't generate any codes, I incorrectly assumed, it must have worked. It probably did exactly what I had asked, but not what I thought I had asked it to do. A good mistake to experience, just because there were no errors, doesn't mean that it did exactly what you thought it did.
Reply


Messages In This Thread
RE: Variable for the value element in the index function?? - by Learner1 - Jan-20-2024, 06:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 687 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,524 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 1,068 Aug-07-2023, 05:58 PM
Last Post: Karp
  Index Function not recognized in Python 3 Peter_B_23 1 1,390 Jan-08-2023, 04:52 AM
Last Post: deanhystad
  Retrieve variable from function labgoggles 2 1,103 Jul-01-2022, 07:23 PM
Last Post: labgoggles
  Cant transfer a variable onto another function KEIKAS 5 1,981 Feb-09-2022, 10:17 PM
Last Post: deanhystad
  myList.insert(index, element) question ChrisF 1 1,696 Aug-27-2021, 03:49 PM
Last Post: bowlofred
  How i can add elements to table index of element blazej2533 3 2,078 Dec-03-2020, 08:16 PM
Last Post: Larz60+
Question Matching variable to a list index Gilush 17 6,104 Nov-30-2020, 01:06 AM
Last Post: Larz60+
  How to get index of minimum element between 3 & 8 in list Mekala 2 2,603 Nov-10-2020, 12:56 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020