question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set all string declarations using f-strings

See original GitHub issue

Once Python 3 support is in, we should port string declaration to using f-strings.

f-strings are much easier to read. for example:

>>> name = "Eric"
>>> age = 74
>>> f"Hello, {name}. You are {age}."
'Hello, Eric. You are 74.'

Can be used in function calls:

>>> def to_lowercase(input):
...     return input.lower()

>>> name = "Eric Idle"
>>> f"{to_lowercase(name)} is funny."
'eric idle is funny.'

There are also much faster then %s and str.format()

This would make a line such as the following, much easier to read:

https://github.com/keylime/keylime/blob/d46237141be8585d337518ec95f91953c637afff/test/test_restful.py#L559

More details here: https://www.python.org/dev/peps/pep-0498/

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:21 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
lukehindscommented, Sep 12, 2019

Just been thinking about this, the best approach (and easier for you) might be to backup your current repository / work cp -r keylime keylime_fstrings

Go into keylime and switch the master branch, grab the changes and merge them into your repo and push them:

git fetch upstream git merge upstream/master master git push origin master

After that create a new branch:

git checkout -b frstings

Then open two editors, one in keylime and one in keylime_fstrings

In a terminal and the original directory keylime_fstrings with your changes run git status or better still git diff and note your changes. Now copy and paste those changes from your editor showing keylime_fstrings into the editor showing keylime

Once all of that is complete, you can then just push your branch and make a pull request.

For upstream to work in git fetch upstream you will need a .git/config like this:

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = git@github.com:amylily1011/keylime.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
[remote "upstream"]
	url = git://github.com/keylime/keylime.git
	fetch = +refs/heads/*:refs/remotes/upstream/*
1reaction
amylily1011commented, Sep 12, 2019

sounds good! @lukehinds. I’ll block the time 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python f-String Tutorial – String Formatting in ... - freeCodeCamp
When using f-Strings to display variables, you only need to specify the names of the variables inside a set of curly braces {}...
Read more >
A Guide to Formatting with f-strings in Python - CIS Sandbox
To use formatted string literals, begin a string with f or F before the opening quotation mark or triple quotation mark in a...
Read more >
f-strings in Python - GeeksforGeeks
The idea behind f-strings is to make string interpolation simpler. To create an f-string, prefix the string with the letter “ f ”....
Read more >
Python 3's f-Strings: An Improved String Formatting Syntax ...
As of Python 3.6, f-strings are a great new way to format strings. Not only are they more readable, more concise, and less...
Read more >
4 Tricks to Use Python F-strings More Efficiently
Thus, the print statements are much more powerful with string interpolation… ... F-strings make it quite simple to place these separators ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found