How to put Code in your blog/article
For programmers, who want to write about their codes. Its often the first…
February 13, 2021
with open(filepath, 'r') as file:
data = file.read()
Above code read whole file at once, but if the files have multiple lines, the result string will have new line characters as well.
This code will gets you a single string as whole content
with open(filepath, 'r') as file:
data = file.read().replace('\n', '')
This code will gets you a single string as whole content
with open('filename') as f:
lines = f.readlines()
Again, this will give new line characters
with open('filename') as f:
lines = [line.rstrip() for line in f]
with open(source_file) as f:
lines = f.read().splitlines()
The best way to open file is with with
keyword, as you do not need to close the file explicitly. It will take care of closing the file handle.
For programmers, who want to write about their codes. Its often the first…
Introduction To give some context, I have two python files. (Both in same folder…
One of the biggest task while writing article or blog is to have right set of…
Introduction to problem So, on my mac, I’ev set timezone to my local city i.e…
Introduction In a normal email sending code from python, I’m getting following…
So, you want to run your code in parallel so that your can process faster, or…
Introduction This post has the complete code to send email through smtp server…
Introduction In a normal email sending code from python, I’m getting following…
Introduction In one of my app, I was using to talk to . I have used some event…
Introduction So you have a Django project, and want to run it using docker image…
Introduction It is very important to introduce few process so that your code and…
Introduction In this post, we will see a sample Jenkin Pipeline Groovy script…