Reputation: 41
My Code:
f=open(keywords_file,"r")
keywords=f.read().split("\n")[0:-1]
f.close()
os.remove(keywords_file)
up.enter_keywords(",".join(keywords))
up.quit()
My file looks like:
Keyword
Keyword2
Keyword3
keyword4
The problem I noticed:
enter_keywords join skips the first line so my end results:
keyword2,keyword3,keyword4
I need:
keyword,keyword2,keyword3,keyword4
Whats wrong with my code?
Upvotes: 0
Views: 176
Reputation: 10170
Try this:
with open(keywords_file, 'r') as f:
keywords = ",".join(line.strip() for line in f)
Upvotes: 3
Reputation: 4547
You are omitting it when you make a slice:
keywords=f.read().split("\n")[0:-1]
instead, you should just do the following:
keywords = [word for word in f]
Upvotes: 1