Archive for the ‘Tutorials’ Category

Reading files using Python

Posted: May 15, 2012 in Tutorials
Tags: ,

There are multiple ways by which you can read files using Python. # Method 1: Using readline() with while loop fo = open(“file1.txt”,”r”) while True: line = fo.readline() if line == ”: break print line, fo.close() # Method 2: Using readline() with while loop fo = open(“file1.txt”,”r”) while True: line = fo.readline() if not line: [...]

In case you have to combine multiple strings and variables in python, you could use following ways: var1 = 5 var2 = 10 print “Value of variable 1 (var1) is “+a+”and Value of Variable 2 (var2) is”,b To combine two strings, we can do : string_nameĀ  = “Hello” + ” World!!” or string_name = “Hello” [...]

Real numbers are basically actual numbers that exists. That includes rational, irrational, whole, integers, and natural numbers. Rational numbers are numbers able to be put as a fraction. Irrational numbers cannot be put as a fraction (ex: 3.141592) Whole numbers are: 0, 1, 2, 3, 4, 5…. Natural numbers are: 1, 2, 3, 4, 5… [...]

For comparing two files on unix, diff utility is often used. In this tutorial I will cover on understanding output generated by diff utility. Unix diff actually works on Longest common sequence algorithm, which means it tries to find the longest common sequence between two files and compares the remaining uncommon part, part which is [...]

set a {a b {c {d e} h} i} set glob_var {} proc list_eval {list_name {prefix {}}} { global glob_var set end_point [expr [llength $list_name] -1] for {set start_point 0} {$start_point <= $end_point} {incr start_point} { if {[llength [lindex $list_name $start_point]] == 1} { puts “Index for [lindex $list_name $start_point] is $prefix$start_point” if {$start_point == [...]

Tcl: SPLIT Command

Posted: May 17, 2011 in Tutorials
Tags: ,

In Tcl (Tool command language), split command can be used to convert a string into list. Converting lists from string allows you to process the part of string with list commands. Syntax: split string ?splitChars? where string is the string that needs to be converted into list elements. where splitchars is words based on which [...]