Docker image for Drupal 7, and Php extension MongoDB installed.
You have drupal 7 image from docker hub, and want to connect tomongo db via php…
May 14, 2019
This post is dedicated for cases where we intend to append a variable value in a string, whether in logs, string message etc.
Just put a character f before your string, and put all variable in between curly braces.
Example
website_name = 'GyanBlog'
year = 2019
print (f'This website: {website_name} has written this post in year: {year}')
>>> This website: GyanBlog has written this post in year: 2019
This is fantastic way of using string formatting, and is quite easily readable too.
Lets look at above example
website_name = 'GyanBlog'
year = 2019
print ('This website: %s has written this post in year: %d' %(website_name, year))
# Note: %s for string, and %d for integers
Its kind of same as above. But, you use curly braces instead of percentage format.
website_name = 'GyanBlog'
year = 2019
print ('This website: {} has written this post in year: {}'.format(website_name, year))
You can use numbers in curly braces if you want to specify which variables comes when:
print ('This website: {0} has written this post in year: {1}. Thanks from {0}'.format(website_name, year))
>>> This website: GyanBlog has written this post in year: 2019. Thanks from GyanBlog
print ('This website: {1} has written this post in year: {0}'.format(website_name, year))
>>> This website: 2019 has written this post in year: GyanBlog
#Note: the position number in curly braces
But, you can not mix them!
print ('This website: {1} has written this post in year: {}'.format(website_name, year))
# error: ValueError: cannot switch from manual field specification to automatic field numbering
You can concatenate strings simply by + operator.
s = 'hi' + ' ' + 'GyanBlog'
print(s)
>>> 'hi GyanBlog'
This is a simple way, but doesn’t look good.
You have drupal 7 image from docker hub, and want to connect tomongo db via php…
This library is ES6, promise compatible. Or, in your package.json file, include…
Introduction We will see how we can install Python from command line using pyenv…
Introduction You are having a form having multiple fields. When you render a…
Introduction Often in automation, we need to install stuff from command line…
You are developing a nodejs web application having some UI and backend APIs…
Introduction In this post we will see following: How to schedule a job on cron…
Introduction There are some cases, where I need another git repository while…
Introduction In this post, we will see how to fetch multiple credentials and…
Introduction I have an automation script, that I want to run on different…
Introduction I had to write a CICD system for one of our project. I had to…
Introduction Java log4j has many ways to initialize and append the desired…