How to read or write files in Python?

Before any files to read we have to know how to Open & Close the files.

# Open Function:

we can open a file using python build in function open()

file_object = open(file_name, file_access_mode )
  • file_name = It is the file name or the full file path.
  • file_access_mode = File access mode is to determine, open file for read, write , append etc.
ModesDescription
rOpens a file for read only purpose.
rbOpen a file for reading only in binary format.
r+Open a file for both operation reading & writing.
rb+Open a file for both reading & writing in binary format.
wOpen a file for writing purpose only.
It overwrites the existing file or otherwise create a new file.
wbOpens a file for writing only in binary format.
It overwrites the existing file or otherwise create a new file.
aOpens a file for appending.
abOpens a file for appending in binary format.
ab+Opens a file for both appending & reading in binary format.
w+Opens a file for both reading & writing format.
wb+Opens a file for both reading & writing in binary format.

# Write Function:


file_content = "This is my First Text."
file_object.write( file_content ) 

# Read Function:

file_object.read()

# Rename Files:

os.rename( old_file_name, new_file_name )

# Delete File:

os.remove( file_name )

# Close File:


file_object.close()

# File Object Attributes:

  • file_object.closed
  • file_object.mode
  • file_object.softspace [ It is no longer supported in python 3.x ]
  • file_object.name

How to redirect to https with www using .htaccess?

First check in your server

Redirect to https and www:

By using the .htaccess technique redirects to the https and www versions of your web pages to https://www.example.com. Add to site’s root .htaccess file:


RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]

Here, Checks if HTTPS is off, or if the request does not include www,
If either condition matches, the request follow the rule and it is redirected to the https://www.example.com

Redirect to https and non-www


RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) https://example.com/$1 [L,R=301]

Best & Cheapest Web Hosting in India for starter with Xozz

We always want to start our own website. But Due to the huge hosting Charge, we avoid our decisions.

I was also finding these types of hosting provider. Initially we don’t have more money to invest on the website & hosting etc. After searching & hosting on many free hosting accounts, I found xozz.in.

Best Web Hosting & Re-seller Hosting in India

Xozz.in is the best for me. I don’t have huge traffic in my website that I have to need more space. Here xozz team are providing the hosting with a minimum costing. If i can afford this hosting you can also. Because after to many searching and hosting on many free server, finally i got my paid hosting with xozz.

Features they are providing Like:

  • Unlimited SSD Disk Space
  • Unlimited Bandwidth
  • Unlimited Database
  • Unlimited Emails
  • Free DOT COM Domain, with exciting offers
  • Powerful RAM
  • Hosting 1 website
  • Cpanel
  • 24×7 Support

Yes, All of these they are providing with a minimum price. I am not Advertising. But I really used their service. Currently I am also using their service (xozz.in).

You can Register your domain name.
Cheap & Best Hosting Plan for Beginners & Developers

Web Hosting & Re-seller Hosting in India
All the features you need to build the website of your dreams – without the hassle.

Really It helps me a lot. When I had not enough money, this hosting helps me.

They are proving few site builders like- Powerful Weebly Site Builder

How to Call a function on close bootstrap modal using Jquery?

Want to run a function , On Close Bootstrap Modal.

# On Show or Open a Bootstrap Modal, Call a function

$('#modal').on('shown.bs.modal', function (e) {
    // Execute Your Codes 
}) 

# On Close or Hide a Bootstrap Modal, Call a function

$('#modal').on('hidden.bs.modal', function (e) {
    // Execute Your Codes 
})

For any suggestion or feedback, queries please comment to improve.