For my project I do some stuff and extract a specific line from the command line output and then insert it into a list. From there I export the list into a trainingfile for a learning algorithm to use later. The problem is when i pull the information off of the command line it pulls
"Number\n"
When i append the list to a text file it doesn't print
Number, Number, Number
Instead it is printing
Number
Number
Number
It is applying the newline character and this is nearly useless to me. With some googling I found this link Strip all the elements of a string list explaining what I thought was exactly what i needed to fix the problem. It strips out the newline character and turns the list into what i need for later use. EXCEPT for whatever reason it isn't working.
Here is my code
def exportlist(self):
file = open('Trainingfile.txt','a+')
# i pass it into a variable since i ran into some odd errors if i try
# to apply the map function to self.vectorlist
my_list= self.vectorlist
print(my_list) # prints [ 'number\n', 'number\n'......]
# WHAT THE ABOVE LINK AND OTHERS SAID SHOULD WORK
strip_list= map(str.rstrip('\n'), my_list)
print(strip_list) # prints "map object at 0x00000002C...."
self.vectorlist = strip_list # test code
print(self.vectorlist) # prints same as strip_list
file.close()
I get similar results if i use chr.split instead of strip. Printing my_list prints the improperly formatted list. printing the strip_list which is supposed to be the properly formatted list, prints what i think is a memory location " 0x0000000002C...." Everything i found online is telling me that it should not be printing this. It should be printing the properly formatted list. Does anyone know why this is happening? This happens everytime i use the map function. I have tried multiple methods to strip "\n" from my list but it always returns the same thing.