Esempio n. 1
0
# doStuff( lambda x=1: print( "slartibartfast %r" % x ) )

# overwrite a method name with another method... wtf... woah... careful
method1()
method1 = method2
method1()

# Enums !!
# from enum import Enum ### don't forget the import as our enum Color is derived from Enum
class Color( Enum ):
    red = 1
    green = 2
    blue = 3

print( "Color: %r" % Color.red )  # NOTE: Python 3+ prints the enum class, name and ordinal

# printing without newline
sys.stdout.write( "this is" )
sys.stdout.write( " on the same line" )
print( "" )

division = 5 / 2
print( "5/2   = %r" % division )

division = 5 / 2.0
print( "5/2.0 = %r" % division )

matchingSymbolString = "{.{.}.}.{.}"
matchingSymbolPos = StrUtl.findMatchingSymbol( matchingSymbolString, "{", "}" )
print( "MatchingSymbolPos: [%r]='%r'" % ( matchingSymbolPos, matchingSymbolString[matchingSymbolPos] ) )
Esempio n. 2
0
opts = GetOpts()
try:
    opts.add( "option", "o", "string", "sample option", True )
    opts.build( sys.argv )
    option = opts.get( "option", 0 )
    print "Option: %s" % option
except Exception as e:
    logging.exception( e )
    print "Invalid Usage: %s" % str( e )
    opts.usage()

bestLibPath = EnvUtl.getBestPythonLibDir()
print "Best Lib Path: '%s'" % bestLibPath

value = None
print( "isString(%r)='%r'" % ( value, StrUtl.isString( value ) ) )

value = "Hello"
print( "isString(%r)='%r'" % ( value, StrUtl.isString( value ) ) )

value = "3.141592653589792"
print( "isString(%r)='%r'" % ( value, StrUtl.isString( value ) ) )

value = None
print( "isNumberString(%r)='%r'" % ( value, StrUtl.isNumberString( value ) ) )

value = "3.141592653589792"
print( "isNumberString(%r)='%r'" % ( value, StrUtl.isNumberString( value ) ) )

value = 3.141592653589792
print( "isNumberString(%r)='%r'" % ( value, StrUtl.isNumberString( value ) ) )