Posts

Showing posts from April, 2017

How to Add / Append items to a list in Python

To add items to a list in python is a very general task that you might come across. Here we have an empty list that we are populating with 10 items using the append method. n = 10 list = [] for i in range(n): list.append(input()) print list That's it! Common Mistake its a common mistake of doing something like this n=10 list=[] for i in range(n): list[i]=input() this will throw an error IndexError: list assignment index out of range Because the list is empty and list[i] is trying to access index which does not exist!

Set Permissions to add files to /var/www folder in ubuntu linux

/var/www is the default root folder of your local web server (like apache ), you host all your website files here and access it on the browser with url like http://127.0.0.1 or http://localhost you cannot simply copy paste stuff in this folder using your file browser, It is protected for security reasons, you will get a permission denied error message because by default you don't have write access permission here. Follow these Steps: execute these commands to set all permissions for /var/www directory sudo adduser <username> www-data sudo chown -R www-data:www-data /var/www sudo chmod -R g+rwX /var/www replace <username> with your actual username. Now you can copy, edit and create files in /var/www folder just like any other folder.