Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str.split unintentionally strips char 'I' from the string #48304

Closed
Govind mannequin opened this issue Oct 6, 2008 · 2 comments
Closed

str.split unintentionally strips char 'I' from the string #48304

Govind mannequin opened this issue Oct 6, 2008 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@Govind
Copy link
Mannequin

Govind mannequin commented Oct 6, 2008

BPO 4054
Nosy @vstinner
Files
  • file.txt: This is the input file that I used to reproduce this issue
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-10-06.13:09:08.062>
    created_at = <Date 2008-10-06.13:04:29.422>
    labels = ['type-bug', 'invalid']
    title = "str.split unintentionally strips char 'I' from the string"
    updated_at = <Date 2008-10-06.13:09:08.060>
    user = 'https://bugs.python.org/Govind'

    bugs.python.org fields:

    activity = <Date 2008-10-06.13:09:08.060>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-10-06.13:09:08.062>
    closer = 'vstinner'
    components = []
    creation = <Date 2008-10-06.13:04:29.422>
    creator = 'Govind'
    dependencies = []
    files = ['11710']
    hgrepos = []
    issue_num = 4054
    keywords = []
    message_count = 2.0
    messages = ['74368', '74370']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'Govind']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4054'
    versions = []

    @Govind
    Copy link
    Mannequin Author

    Govind mannequin commented Oct 6, 2008

    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

    @Govind Govind mannequin added the type-bug An unexpected behavior, bug, or error label Oct 6, 2008
    @vstinner
    Copy link
    Member

    vstinner commented Oct 6, 2008

    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.

    @vstinner vstinner closed this as completed Oct 6, 2008
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant