devxlogo

devx-admin

Check for finite numbers in Python

Use the math module???s isfinite method to determine if a value is finite or not.  If it is not a number, the function returns false.  See below for an example:math.isfinite(10) returns True

How to detect Python version at runtime

At times, we want to run our code only if the version of Python engine is above a certain version. See below for sample code. Import sysversion = sys.version

Return multiple values from a function in python

Python can return multiple values at a time. See below for a simple example. def multipleValueFunc():     z = 11     b = 22    return z, b  j,k  = multipleValueFunc () print(j, k) 

Reverse a string in Python

Its pretty ease to reverse a string in Python. ???Devx Jan???[::-1]  gives ???naJ xveD???

Simplifying Null Check in Java

To avoid null exceptions, we usually validate against null and emptiness as shown: if(object != null && !object.equals(“”)) {} We can simplify this as below: if(!””.equals(object)){}

Using Find_in_Set in MySQL

MySQL has various ways to search for or lookup a given string. One such powerful mechanism is by using FIND_IN_SET. This function enables a lookup for a given string in

Get All the Tables with a Count of Their Records

Get all the tables with a count of their records with the following query: CREATE TABLE #Temp ( TableName VARCHAR(MAX), Rows INT ); EXEC sp_MSForEachTable @command1 = ‘INSERT INTO #Temp(TableName,

Use the Namespace Alias for Better Readability

For better readability, C# provides a way to shorten the namespaces with an alias. Please see below for an example: using ExcelInterop = Microsoft.Office.Interop.Excel;var excelInteropApplication = new ExcelInterop.Application();