Python Setup with Example

Python is simple to use, but it is a real programming language, offering much more structure and support for large programs than shell scripts or batch files can offer. On the other hand, Python also offers much more error checking than C, and, being a very-high-level language

Python is an interpreted language, which can save you considerable time during program development because no compilation and linking is necessary

Python enables programs to be written compactly and readably. Programs written in Python are typically much shorter than equivalent C, C++, or Java programs, for several reasons:

  • the high-level data types allow you to express complex operations in a single statement;
  • statement grouping is done by indentation instead of beginning and ending brackets;
  • no variable or argument declarations are necessary.

Installation

Download 32bit or 64bit exe from https://www.python.org/downloads/windows/

Setup environment variable ex. in the path variable add

C:\Python35;C:\Python35\Scripts;

To verify open cmd and type pip

Install selenium

cmd > pip install selenium

installpythonselenium

Open python shell to play with some useful commends

python_shell

Installing Python in Eclipse

  1. Unzip eclipse-standard-luna-R-win32.zip, the file that you just downloaded and moved.
    On my machine (running Windows 7), I can
  • Right-click the file.
  • Hover over the IZArc command from the menu of options.
  • Click Extract Here

2. Open Eclipse > Click on Help then click Install New Software… in its pull-down menu, as shown below.

3. Enter the text (or cut/paste from this document) http://pydev.org/updates into the Work with text box and press Enter.

In a few seconds the information under Name should change from
There is no site selected to Pending to

Select only the top PyDev checkbox; do NOT select the PyDev Mylyn Integration (optional) box.
Check before proceeding that the Install pop-up window appears as

4. Click Next >

A new Install pop-up window will appear.

Select the I accept the terms of the license agreement radio button, so the window appears as

5. Check the box labeled Brainwy Software; Pydev; Brainwy.

Check before proceeding that the Install pop-up window appears as

 

  • Click OKThe installation will finish (showing the final progress bars).A Software Updates pop-up window will appear.
  • Click YesEclipse will terminate and restart. As you did in step 3, click OK to the Workspace Launcher pop-up window.
  • Click Window (to the left of Help on the far right of the line below this window’s blue title Java – Eclipse) and then click Preferences in its pull-down menu, as shown below.
  • Drill down to select the interpreter:
    • Disclose PyDev by clicking the + in front of PyDev or double-clicking PyDev (after the +); the + changes to a .
    • Disclose Interpreters by clicking the + in front of Interpreters or double-clicking Interpreters (after the +); the + changes to a .
    • Select Python – Interpreter.

    The Preferences pop-up window should appear as follows

  • Click New… at the top-right of the top windowA Select Interpreter pop-up window appears.Type Python34 in the Interpreter Name text box.
    Type (or cut/paste) C:\Python34\python.exe in the Interpreter Executable text box (or browse to this file).
    The Select Interpreter pop-up window should appear as
  • Click OK.A Selection needed pop-up window will appear.PythoneclipsEnsure that a check appears in all four checkboxes.
  • Click OK.The Preferences pop-up window will be changed to
  • Click OK.A Progress Information pop-up window will appear.During installation, it will show the various operations it is performing and a progress bar for each one. Eventually the installation will terminate.

    If the following pop-up window appears

 

  • Click Window (to the left of Help on the far right of the line below this window’s blue title Java – Eclipse SDK), hover over Open Perspective in the pull-down menu and then click Other… in the next pull-down menu.The Open Perspective pop-up window will appear.
  • Double-click PyDev (third from the bottom)The blue label on the Eclipse window will change to PyDev – Eclipse, the Package Explorer in the upper-left tab will change to PyDev Package Explorer, and a PyDev icon will appear to the right of the Java icon.

Congratulation! Eclipse is now installed for Python

 Your first Python program in Eclipse

Select File -> New -> Project. Select Pydev -> Pydev Project.

Create a new project with the name “de.vogella.python.first”. Select Python version 2.6 and your interpreter.

Press finish.

Select Window->Open Perspective ->Other. Select the PyDev perspective.

Select the “src” folder of your project, right-click it and select New -> PyDev Modul. Create a module “FirstModule”.

Create the following source code.

'''
Created on Apr 15, 2016

@author: Samir Patel
'''
def add(a,b):
    return a+b

def addFixedValue(a):
  y = 5
  return y +a
  
print add(1,2)
print addFixedValue(1)

Right-click your model and select Run As -> Python run.

Congratulations! You created your first (little) Python modul and ran it!

 

 

Advertisements

About samp79

Professional Automation Tester
This entry was posted in Python. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s