This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: str.split unintentionally strips char 'I' from the string
Type: behavior Stage:
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Govind, vstinner
Priority: normal Keywords:

Created on 2008-10-06 13:04 by Govind, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
file.txt Govind, 2008-10-06 13:04 This is the input file that I used to reproduce this issue
Messages (2)
msg74368 - (view) Author: Govind (Govind) Date: 2008-10-06 13:04
I tried to process a text file (with UTF-8 encoding) which has 
contents like this:


FILE=India
asbds
FILE=Indonasia
ssgsds
FILE=Africa
DBGDGDFG

When I use the below code:
>>> f = open("e:\\temp\\file.txt", 'r')
>>> lines = f.readlines()
>>> for line in lines:
	if line.startswith("FILE="):
		print line.strip("FILE=")


I get output as:
ndia

ndonasia

Africa


I is always stripped if it follows the substring that I want to strip 
off.

Am I doing something wrong here or is this a bug in Python?

-Govind
msg74370 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-10-06 13:09
It's not a bug. Please read the documentation of the split() method:
   http://docs.python.org/library/stdtypes.html#str.split

If you want to get the value after "=", use:
   value = line.split("FILE=", 1)[1]
or:
   value = line[len('FILE='):]
or:
   value = line.partition('FILE=')[2]
or:
   etc.
History
Date User Action Args
2022-04-11 14:56:40adminsetgithub: 48304
2008-10-06 13:09:08vstinnersetstatus: open -> closed
resolution: not a bug
messages: + msg74370
nosy: + vstinner
2008-10-06 13:04:29Govindcreate