Subscribe:

Ads 468x60px

Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Wednesday, November 21, 2025

How to open and close a process from a python script

Hi guys

     I am giving some idea about  how we can start and stop a process using a python script. This will be useful when we need to start a process that is outside the script

I am running two python scripts. One is master script, this script will start the slave script. Slave script will execute continuously upto 5 sec and it will terminated by the master script

Master script

 #!/usr/bin/python  
 import time  
 import subprocess  
 #starting process python while.py  
 proc = subprocess.Popen(["python","while.py"],shell=False)  
 #5 sec delay  
 time.sleep(5)  
 #killing process  
 subprocess.call(["kill","-9","%d" % proc.pid])  
 #waiting for killing  
 proc.wait()  
 print 'poll = ',proc.poll()  


Slave script


 #!/usr/bin/python  
 while 1:  
      print "hello"  


Output
--------

It will print hello upto 5 seconds after that it will stop and show this message







Sunday, September 25, 2026

PyQT Tutorial:Introduction

Hi all

        PyQT is an easier way of creating User Interface .It has a power of both  Python and Qt.

What is Python
  • A high level Programming language 
  • An Object Oriented Programming Language
  • A scripting Language



  • Qt is a cross platform application framework for GUI Development
  • Qt stands for Qroll Tech.It is founded by Qroll Tech  now owned by Nokia

http://en.wikipedia.org/wiki/Python_(programming_language)


How PyQT Works


      Qt is used to make the User Interface file (.ui) .After making the user interface file(ui) ,converting it into equivalent python code .The code is generated using pyuic compiler .After modification some modification ,we can run the python code file ,




Requirements in Linux(Ubuntu )
  • Qt 4 Designer or  Qt4 Creator
  • python-qt4 : Python bindings for Qt4
  • pyqt-tools : pyuic and pylupdate for Qt3



Example demo 


1)Hello World Program using PyQt











Thank You for watching...




Friday, September 9, 2026

Python Programming Tutorial Part 3:Hello World

Hi all

             We can start programming using  Python .I am running python in Ubuntu 10.04 and using version python 2.6.5 . We can start with "hello world program" .You can either use interpreter or can write source code with extension .py .The standard way of programming is writing code .I am demonstrating the source code here.

Hello World using Python


Take a text editor and type this code and save it with some filename ,for eg test.py 


#!/usr/bin/env python
print "Hello World"
After saving the file ,Take terminal in the following file-path,type the following command to execute
python test.py
The Output will look like this
Hello World

Python Tutorial Part 2:How to install Python

Python is a cross-platform compatible language .We can install Python in Windows ,Linux and MacOSX .The download link for each platform is given Below



For Windows ,Linux and MacOSX


For  Windows ,we need to download the installer separately .For GNU/Linux such as Ubuntu,Debian and MacOSX have pre-installed Python .

Python can be  programmed in two ways ,It has an interpreter and also we can program  via writing source with extention ".py" .

Python command Interpreter

IDLE Python:GUI of Interpreter


Python Programming Tutorial Part 1 : What is Python??

Python is a general purpose high level language ,its an Object oriented Programming Language .It is very powerful and also simple  .Python  features are ,it is fully dynamic and has automatic memory management .The library of Python language is very huge . 
               Python is a scripting language like Perl,Ruby,Scheme etc..The main reasons why programmers selected python because of the following reason



Software quality
    For many, Python’s focus on readability, coherence, and software quality in gen-
    eral sets it apart from other tools in the scripting world. Python code is designed
    to be readable, and hence, reusable and maintainable—much more so than tra-
    ditional scripting languages. The uniformity of Python code makes it easy to
    understand, even if you did not write it. In addition, Python has deep support
    for more advanced software reuse mechanisms, such as object-oriented program-
    ming (OOP).
                                                                                      3
Developer productivity
    Python boosts developer productivity many times beyond compiled or statically
    typed languages such as C, C++, and Java. Python code is typically one-third to
    one-fifth the size of equivalent C++ or Java code. That means there is less to
    type, less to debug, and less to maintain after the fact. Python programs also run
    immediately, without the lengthy compile and link steps of some other tools,
    further boosting programmer speed.

Program portability
    Most Python programs run unchanged on all major computer platforms. Port-
    ing Python code between Linux and Windows, for example, is usually just a
    matter of copying a script’s code between machines. Moreover, Python offers
    multiple options for coding portable graphical user interfaces, database access
    programs, web-based systems, and more. Even operating system interfaces,
    including program launches and directory processing, are as portable in Python
    as they can possibly be.

Support libraries
    Python comes with a large collection of prebuilt and portable functionality,
    known as the standard library. This library supports an array of application-level
    programming tasks, from text pattern matching to network scripting. In addition,
    Python can be extended with both homegrown libraries and a vast collection of
    third-party application support software. Python’s third-party domain offers tools
    for web site construction, numeric programming, serial port access, game devel-
    opment, and much more. The NumPy extension, for instance, has been
    described as a free and more powerful equivalent to the Matlab numeric pro-
    gramming system.

Component integration
    Python scripts can easily communicate with other parts of an application, using
    a variety of integration mechanisms. Such integrations allow Python to be used
    as a product customization and extension tool. Today, Python code can invoke
    C and C++ libraries, can be called from C and C++ programs, can integrate with
    Java components, can communicate over frameworks such as COM and .NET,
    and can interact over networks with interfaces like SOAP, XML-RPC, and
    CORBA. It is not a standalone tool.

Enjoyment
    Because of Python’s ease of use and built-in toolset, it can make the act of
    programming more pleasure than chore. Although this may be an intangible
    benefit, its effect on productivity is an important asset.

From this reason ,the developer productivity is the important one .Python saves  a good amount of time for coding .

What  is the Downside of Python

 The main drawback of Python when compared with C and C++ is its execution speed . Python is not creating executable ,instead it create a intermediate code called byte code .This byte code is slower than the compiled C or C++ executables..

Who Uses Python Today??

1) Google makes extensive use of Python in its web search system, and employs  Python’s creator.

 2)The YouTube video sharing service is largely written in Python.

 3)The popular BitTorrent peer-to-peer file sharing system is a Python program.

 4)Intel, Cisco, Hewlett-Packard, Seagate, Qualcomm, and IBM use Python for  hardware testing.

 5)Industrial Light & Magic, Pixar, and others use Python in the production of  movie animation.

 6)JPMorgan Chase, UBS, Getco, and Citadel apply Python for financial market forecasting.

7)NASA, Los Alamos, Fermilab, JPL, and others use Python for scientific programming tasks.

 8)iRobot uses Python to develop commercial robotic vacuum cleaners.

 9)ESRI uses Python as an end-user customization tool for its popular GIS mapping  products.

 10)The NSA uses Python for cryptography and intelligence analysis.

 11)The IronPort email server product uses more than 1 million lines of Python code   to do its job.

 12)The One Laptop Per Child (OLPC) project builds its user interface and activity  model in Python.

What Can I do with Python??

  • System Programming
  • GUI
  • Internet Scripting
  • DataBase Programming
  • Numeric and Scientific Programming
  • Gaming,AI,XML,Robots