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

Add discussion of trailing backslash in raw string to tutorial #55688

Closed
bitdancer opened this issue Mar 13, 2011 · 9 comments
Closed

Add discussion of trailing backslash in raw string to tutorial #55688

bitdancer opened this issue Mar 13, 2011 · 9 comments
Labels
3.9 3.10 3.11 docs Documentation in the Doc dir easy type-feature A feature request or enhancement

Comments

@bitdancer
Copy link
Member

bitdancer commented Mar 13, 2011

BPO 11479
Nosy @birkenfeld, @facundobatista, @ezio-melotti, @bitdancer, @iritkatriel, @dancinglightning
PRs
  • bpo-11479: Added a discussion of trailing backslash in raw string to tutorial #27949
  • Files
  • tutorial-raw-string.patch
  • 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 = None
    created_at = <Date 2011-03-13.03:10:02.668>
    labels = ['easy', '3.9', '3.10', '3.11', 'type-feature', 'docs']
    title = 'Add discussion of trailing backslash in raw string to tutorial'
    updated_at = <Date 2021-08-25.15:52:29.825>
    user = 'https://github.com/bitdancer'

    bugs.python.org fields:

    activity = <Date 2021-08-25.15:52:29.825>
    actor = 'dancinglightning'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2011-03-13.03:10:02.668>
    creator = 'r.david.murray'
    dependencies = []
    files = ['21097']
    hgrepos = []
    issue_num = 11479
    keywords = ['patch', 'easy']
    message_count = 9.0
    messages = ['130720', '130727', '130739', '130742', '130743', '130744', '130748', '227698', '399988']
    nosy_count = 11.0
    nosy_names = ['georg.brandl', 'facundobatista', 'QuantumTim', 'ezio.melotti', 'v+python', 'r.david.murray', 'eli.bendersky', 'docs@python', 'gwideman', 'iritkatriel', 'dancinglightning']
    pr_nums = ['27949']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue11479'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Linked PRs

    @bitdancer
    Copy link
    Member Author

    bitdancer commented Mar 13, 2011

    Here is a proposed addition to the tutorial noting the problem with using raw strings for windows paths and how to work around it.

    @bitdancer bitdancer added the type-bug An unexpected behavior, bug, or error label Mar 13, 2011
    @bitdancer bitdancer added the docs Documentation in the Doc dir label Mar 13, 2011
    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Mar 13, 2011

    Would it not be better to just recommend Windows users not to put that last backslash in at all? IIUC it's only needed to later append file names to directory names, but that's better achieved with os.path.join

    @gwideman
    Copy link
    Mannequin

    gwideman mannequin commented Mar 13, 2011

    Eli: Excellent and thoughtful point. This would indeed be exactly the place to suggest os.path.join as an alternative.

    In addition, there are still occasions where one needs to form a string with trailing backslash. Two examples:

    1. When writing the string specifying root directory: r'C:\ '[:-1]
    2. Using python to prepare command lines to run other command line programs, where an argument may require a final backslash to explicitly specify a target directory (as opposed to a file).

    @ezio-melotti
    Copy link
    Member

    ezio-melotti commented Mar 13, 2011

    I would rephrase:
    +There is one subtle aspect to raw strings that is of special concern to Windows
    +programmers: a raw string may not end in an odd number of \ characters.

    to something like:
    +There is one subtle aspect to raw strings: a raw string may not end in
    +an odd number of \ characters. That is of special concern while
    +dealing with Windows paths.

    Otherwise it seems that this problem only affects raw strings on Windows.

    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Mar 13, 2011

    Ezio Melotti ezio.melotti@gmail.com added the comment:

    I would rephrase:
    +There is one subtle aspect to raw strings that is of special concern to
    Windows
    +programmers: a raw string may not end in an odd number of \
    characters.

    to something like:
    +There is one subtle aspect to raw strings: a raw string may not end in
    +an odd number of \ characters. That is of special concern while
    +dealing with Windows paths.

    Otherwise it seems that this problem only affects raw strings on Windows.

    I agree, but I'd also say something about os.path.join when mentioning
    Windows paths, because the vast majority of problems that require the
    trailing backslashes can be solved with it.

    @ezio-melotti
    Copy link
    Member

    ezio-melotti commented Mar 13, 2011

    That would of course be a good addition too.

    @bitdancer
    Copy link
    Member Author

    bitdancer commented Mar 13, 2011

    Well, the problem with both [:-1] and os.path.join is that they are inappropriate for that section of the tutorial. I considered putting the discussion later in the section so that I could use [:-1] (which hasn't been introduced at that point), but it made the flow even worse than adding the text where I did. I suppose the os.path.join could be put in if the sentence was short and cross referenced the library docs rather than going into a detailed example.

    @ezio-melotti ezio-melotti added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Nov 8, 2012
    @serhiy-storchaka serhiy-storchaka changed the title Add discussion of trailing slash in raw string to tutorial Add discussion of trailing backslash in raw string to tutorial Nov 8, 2012
    @bitdancer
    Copy link
    Member Author

    bitdancer commented Sep 27, 2014

    I'm on a quest to clear my 'commit ready' queue. This issue needs to go back to 'needs patch' stage...I'll leave it to someone else to rewrite my original patch based on the feedback, since it is unlikely I will get back to it any time soon. I'll commit it if someone else does the revision and moves it back to commit review, though ;)

    @iritkatriel
    Copy link
    Member

    iritkatriel commented Aug 20, 2021

    The patch needs to be converted into a github PR, and modified according to the feedback on this issue.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    hauntsaninja added a commit that referenced this issue Dec 28, 2022
    Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 28, 2022
    …thonGH-94768)
    
    (cherry picked from commit b95b1b3)
    
    Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
    Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 28, 2022
    …thonGH-94768)
    
    (cherry picked from commit b95b1b3)
    
    Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
    Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
    miss-islington added a commit that referenced this issue Dec 28, 2022
    (cherry picked from commit b95b1b3)
    
    Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
    Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
    miss-islington added a commit that referenced this issue Dec 28, 2022
    (cherry picked from commit b95b1b3)
    
    Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
    Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 3.10 3.11 docs Documentation in the Doc dir easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants