Drupal 7 - Code for Exporting all your content nodes in json files
Introduction When I migrated all of my drupal-7 website to drupal-8, I wrote…
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.
Introduction When I migrated all of my drupal-7 website to drupal-8, I wrote…
Introduction In my previous article, I explained How to have set of fields and…
After 2 days, there was my demo. I deployed my nodejs code on lambda function…
Introduction I had to develop a small automation to query some old mysql data…
If your youtube video looks like:https://www.youtube.com/watch?v=g0kFl7sBdDQ…
Introduction You already have a content type with one or more fields in it…
Introduction Strapi is a backend system provides basic crud operations with…
Introduction I had to create many repositories in an Github organization. I…
Introduction I was trying to download some youtube videos for my kids. As I have…
Introduction In this post, we will explore some useful command line options for…
Introduction In this post, we will see how we can apply a patch to Python and…
Introduction We will introduce a Package Manager for Windows: . In automations…