Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Monday, 1 August 2016

Tutorial: File Reading and Writing Methods

1)
Create an empty text file.

>>>fo = open("my_file.txt", "w")        # The file is newly created  
>>>fo.close()                                    # Closing file. VERY IMPORTANT!




Now we create an empty file "my_file.txt" with mode "w".


2)  
Write to the file.

Next i am going to write something to this file, for that we have to open the file with "w" write mode ok

>>>fw = open("my_file.txt", "w")     
>>>fw.write("Hai Friends..")                # .write(str)
>>>fw.close()




3)
Read from a file.

Next i am going to read the content from this file and print it on the console, for that open the file with "r" mode

>>>fr = open("my_file.txt", "r")
>>>content = fr.read()                       # .read()
>>>print content
>>>fr.close()


Tutorial: How to Run a Python Program on Terminal



1)
Craete a python file.

First i am going to create a simple python program to print "HAI FRIENDSSS", For that open a text file and write "print "HAI FRIENDSSS"", And save that text file with extension ".py".






Then open the terminal and go to the folder where the python file is saved

2)
Run python command on terminal.

Syntax:
"python filename.py"




 Then you will get the out put "HAI FRIENDSSS". In this way you can run python programs on terminal

Tuesday, 20 October 2015

Windows 10 Python Django Tutorial - Writing your first app

1)
Create a project


>django-admin startproject mysite

>dir mysite

>dir mysite\mysite

2)
Create default database and tables


>cd mysite

>python manage.py migrate

3)
Check default sqllite3 database "db.sqllite3"


>dir

4)
Verify your Django project.


a)
Run development server
>python manage.py runserver

b)
Goto http://127.0.0.1:8000/



How To Install Python and Virtualenv In Windows 10

1)
INSTALL PYTHON
---------------------------
a)
Goto https://www.python.org/downloads/

b)
Download and Install Python

c)
Open command prompt and type python to verify the installation

2)
INSTALL VIRTUALENV
-------------------------------------
a)
Goto https://pypi.python.org/pypi/virtualenv

b)
download virtualenv-13.1.2.tar.gz (md5, pgp)

c)
Extract "virtualenv-13.1.2.tar.gz"

d)
Open command prompt then cd to following path
>cd C:\Users\anusree\Downloads\dist\virtualenv-13.1.2

e)
Install virtualenv
>python setup.py install


3)
CREATE AND ACTIVATE VIRTUALENVIRONMENT
-----------------------------------------------------------------------------
a)
Create virtualenv named "myenv"
>python -m virtualenv myenv
>dir

b)

Activate virtualenvironment "myenv"
>C:\Users\anusree>.\myenv\Scripts\activate
(myenv) C:\Users\anusree>

Monday, 19 October 2015

How to Install Python and Django on Windows 10

1)
INSTALL PYTHON
---------------------------
a)
Goto https://www.python.org/downloads/

b)
Download and Install Python

c)
Open command prompt and type python to verify the installation

2)
INSTALL VIRTUALENV
-------------------------------------
a)
Goto https://pypi.python.org/pypi/virtualenv

b)
download virtualenv-13.1.2.tar.gz (md5, pgp)

c)
Extract "virtualenv-13.1.2.tar.gz"

d)
Open command prompt then cd to following path
>cd C:\Users\anusree\Downloads\dist\virtualenv-13.1.2

e)
Install virtualenv
>python setup.py install


3)
CREATE AND ACTIVATE VIRTUALENVIRONMENT
-----------------------------------------------------------------------------
a)
Create virtualenv named "myenv"
>python -m virtualenv myenv
>dir

b)

Activate virtualenvironment "myenv"
>C:\Users\anusree>.\myenv\Scripts\activate
(myenv) C:\Users\anusree>


4)
INSTALL DJANGO
-----------------------------
a)
Install Django
(myenv) C:\Users\anusree>pip install django
Collecting django
  Downloading Django-1.8.5-py2.py3-none-any.whl (6.2MB)
    100% |################################| 6.2MB 48kB/s
Installing collected packages: django
Successfully installed django-1.8.5
(myenv) C:\Users\anusree>

b)
Verify the installation of Django
(myenv) C:\Users\anusree>python
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import django
>>>