Wednesday, February 3, 2016

Introduction to Python - Course Overview

Webucator.com

In this Python training course, students learn to program in Python. The course is aimed at students new to the language who may or may not have experience with other programming languages.
This Python course is taught using Python 3; however, differences between Python 2 and Python 3 are noted. For private Python classes, our instructor can focus specifically on Python 2 if desired.




Class Goals

  • Learn how Python works and what it's good for.
  • Understand Python's place in the world of programming languages.
  • Learn to work with and manipulate strings in Python.
  • Learn to perform math operations with Python.
  • Learn to work with Python sequences: lists, arrays, dictionaries, and sets.
  • Learn to collect user input and output results.
  • Learn flow control processing in Python.
  • Learn to write to and read from files using Python.
  • Learn to write functions in Python.
  • Learn to handle exceptions in Python.
  • Learn to work with dates and times in Python.

Friday, February 27, 2015

Python: Copy Folder or Files using password (sudo)

Following code can be used to copy Folder or Files using sudo with password.

   def copyFolderOrFile(self, sourcePath, destinationPath):  
     if(os.path.isdir(sourcePath)==True):  
       os.chdir("/some_root_location/")  
       sudoPassword = 'password_of_user_having_sudo_rights'  
       try:  
         command="cp -R "+sourcePath+" "+destinationPath  
         os.system('echo %s|sudo -S %s' % (sudoPassword, command))  
         print "Directory Copied Sucessfully"  
       except OSError as exc:  
         if exc.errno == errno.ENOTDIR:  
           command="cp "+sourcePath+" "+destinationPath  
           os.system('echo %s|sudo -S %s' % (sudoPassword, command))  
           print "File Copied Sucessfully"  
         else:  
           print('Directory/File not copied. Error: %s' % exc)  

More suggestion are always welcome. In case if you wish me to write about any specific scenario, please feel free to write to me or else you can Comment below.

Monday, January 5, 2015

Java: Example of Wait Method in Java

Following is an example to implement Wait Method for predefined seconds in Java. Useful in Selenium, when you don't have control to wait for some element to load in Rich-faces, etc.

 package selenium;  
 import java.util.concurrent.TimeUnit;  
 import org.apache.log4j.Logger;  
 public class WaitMethod  
 {  
   protected void waitForAFewSecond(int timeS)  
   {  
     try  
     {  
       long timeInMS, timeInSec, timeOutMS, timeOutSec;  
       timeInMS = System.currentTimeMillis();  
       timeInSec = TimeUnit.MILLISECONDS.toSeconds(timeInMS);  
       do  
       {  
         timeOutMS = System.currentTimeMillis();  
         timeOutSec = TimeUnit.MILLISECONDS.toSeconds(timeOutMS);  
       }  
       while (timeOutSec - timeInSec < timeS);  
     }  
     catch (Exception e)  
     {  
       System.out.println(e.getMessage());  
     }  
   }  
 }