Tuesday, July 19, 2022

Simple Python Calculator

 My background is C - system programming. Switching to Python with so much libraries and functionalities make it a little over whelming. I wrote a simple calculator that rhythms with code we normally write with C. 


First I wrote a simple calculator function, very straight you can practice by changing if to switch statement 

import os


def Calculation(a, b, operation):

    if(operation=='+'):

        return(a+b);

    if(operation=='-'):

        return(a-b);

    if(operation=='*'):

        return(a*b);

    if(operation=='/'):

        return(a/b);



Below is the similar to the main program of 'C'.

while(1):

    

    print('Welcome to Sam''s Calculator \n')

    print('Press Q any time to exit the calcultaor \n')

    a = input('Please enter the first input =  ')

    b = input('Please enter the second input =  ')

    op= input('Please select the operation to be performed =  ')

    

    if(a=='Q'or a=='q' or b=='Q' or b=='q' or op=='Q' or op=='q' ):

        print('Thank you for using Sam''s Simple calcultaor. Calculator is now exiting \n')

        break

    a = int(a)

    b = int(b)

    result= Calculation(a,b, op)


    print("Result of the operation ",op," = ",result)

Monday, June 6, 2022

Tensor Flow error : module 'tensorflow' has no attribute 'gfile'

Background: This gfile is still present in tensorflow. This occur due to version change in Tensorflow.


  File "/Users/MRJ/anaconda3/envs/python37-tf2.1/lib/python3.7/
site-packages/object_detection/utils/label_map_util.py",
line 137, in load_labelmap

with tf.gfile.GFile(path, 'r') as fid:
  AttributeError: module 'tensorflow' has no attribute 'gfile'




Solution:

We need to update the file with the new  key word tf.io.gfile.GFile where the error is occurring. 

version 1.xx points to tf.gfile.GFile change for new version 2.xx is tf.io.gfile.GFile

Normally this is updated in config_util.py. The error will point which file(s) need to be updated. Once file is updated and saved.  Shutdown and restart the jupyter notebook to take effect.





Wednesday, June 1, 2022

SSIS: export to csv flat file destination task: The code page on input column error 1252 and is required to be 65001

exporting data to flat files. We sometime see error for code page 1252   and is required to be 65001 or it can be vice versa.


ADDITIONAL INFORMATION:

Error at export data to csv [Flat File Destination [187]]: The code page on input column "..." (958) is 1252 and is required to be 65001.


Issue:

Data output from sqlserver by default (This can be updated to other compatible formats) come in ANSI - Latin file format i.e. 1252.  65001 is value for the unicode file (i.e. UTF-8)

The error caused in code pages because 1252 (i.e. Windows-1252) is output from SQL Server and 65001 (i.e. UTF-8) that your CSV file is expecting. 


Solution:

There are two solutions:

1) Select the file connection in SSIS --> Open the properties window and update the code page to the required value as below.



2) Update the SQL code to the unicode format i.e. convert / cast all fields to nvarchar

e.g. select CONVERT(nvhar(10),GETDATE()) DATE 

Popular Posts