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

Allow the usage of the grave accent character (`) for string literals and string formatting #125418

Closed
harmin-parra opened this issue Oct 13, 2024 · 5 comments
Labels
type-feature A feature request or enhancement

Comments

@harmin-parra
Copy link

harmin-parra commented Oct 13, 2024

Feature or enhancement

Proposal:

Currently, string literals in python are surrounded by apostrophes (') or quotation marks (")

a = "first string"
b = 'second string'

The inconvenience is that if we want a string containing both ' and ", we need to escape them

c = "string with \" and ' characters"
d = 'string with " and \' characters'
e = f"string {a} with \" and {b} with ' characters"

It would be nice to use the accent character as a third option to surround string literals and string substitutions, so I can do

f = `string with " and ' characters without escaping`
g = f`string {a} with " and {b} with ' characters without escaping`

It is the case with Javascript and node.js

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

@harmin-parra harmin-parra added the type-feature A feature request or enhancement label Oct 13, 2024
@rruuaanng
Copy link
Contributor

This may add an additional string representation, which I think should be considered seriously, rather than blindly following the implementation of other languages. I'm trying to test this change.

@rruuaanng
Copy link
Contributor

rruuaanng commented Oct 14, 2024

I almost forgot, it seems that this can meet your need

s = ''' 'a' "b" '''
s = f''' '{1}' "{1}" '''

@skirpichev
Copy link
Member

Yet another type of quotes is not a minor feature request - this is something, that should be discussed on https://discuss.python.org/c/ideas/6 first. Then we can consider to reopen this issue.

@skirpichev skirpichev closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2024
@terryjreedy
Copy link
Member

Backticks were part of Python syntax until 2.7 as +- equivalent to repr. They were not popular with most people and reuse would face opposition. Any discussion should start with a review of the discussion then.

@harmin-parra
Copy link
Author

I almost forgot, it seems that this can meet your need

s = ''' 'a' "b" '''
s = f''' '{1}' "{1}" '''

Thanks for the tip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants