While editing someone else's abandoned Python script, I was trying to use
mystring.find("\n", i)
to get the index of the next newline in a string. But this consistently returns -1 (even when I try using "\r\n" instead of "\n"). I know there are newlines in the string, because I had just loaded it from a file. I am not very familiar with Python; am I missing something obvious?
EDIT: Yes, I tried printing out the string. It looks something like this:
expirydate = { year = 1820 }
minimum = { 500 }
extra = { }
The person who originally wrote the script apparently decided that it's better to load the entire file into memory before parsing it.
EDIT2: repr(mystring) looks like this (truncated again):
expirydate = { year = 1820 }\n minimum = { 500 }\n extra = { }\n
EDIT3: As some people suspected, I was misunderstanding the input. Apparently, it was actually searching in a substring of the full input, and the substring simply didn't have a newline. Unfortunately, this still doesn't explain why the script doesn't work, but it helps me get a little closer. I'm closing this question and voting up everyone who took the time to answer. :)