ezoic

Wednesday, August 24, 2016

How to output oracle sql results to a file without showing the results on screen

SET TERMOUT OFF;
SET WRAP OFF;
set pagesize 0;

SET COLSEP '|'
SET LINESIZE 32767

set trimspool on

spool C:\XXX\a.txt
select fox_id,fox_version_id, fin_prod_id, title_desc from zr_edm_global_title where rownum<500 ;

spool off;
exit;
the above statement can output oracle sql results to a file without showing the results on screen, and the output will be shown line by line. 


Tuesday, August 16, 2016

Given a list of single-digited integer, count how many times each digit appears

Given a list of single-digited  integer, count how many times each digit appears

Python code, now you can see the power of dictionary:

a={}
a={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0}


b=[2,3,4,5,4,5,6]

for i in range(len(b)):
    for key in a.keys():
        if b[i]==key:
            a[key]=a[key]+1


Wednesday, July 27, 2016

How to pratically learn python from zero: chapter three loops

In programming, loops is used to complete a round of calculations etc.  through a list etc. Ppl use the framework/form to complete a sequence of  calculations etc. through a list etc.

You can loop through a list, a tuple, a sequence, a set etc.

Python has two types of loops, 1. While 2. For

Python does not have do until loop.

Here are the examples for 1.While and 2.For:


Python's while loop does not include 'do' statement:

count=0 
while (count<9):
    count=count+1    print count





For loop example:
a={1,2,3,4}
for i in range(len(list(a))):
    a=list(a)
    print a[i]
 
set does not support indexing, so convert the set to list.

b=[1,2,3,4]
for i in range(len(b)):
    print b[i]

d=(1,2,3,4)

for i in range(len(d)):
    print d[i]
 
We can loop through a dictionary:
 
kk={'a':1,'b':3,'r':8}

for key in kk.keys():
    print key, kk[key]
 
results:
a 1
b 3
r 8
 



And there are three control statements for Python loop: break, continue, pass

Break means the loop stops at where the condition meets:

count=0
while (count<9):
  count=count+1
  if count>5:
        break
  else:
     print count

output

1
2
3
4
5



Pass means we skip the step where the condition meets, it is a little bit similar to break.
 
count=0
 
while (count<9):
    count=count+1
    if count==5:
       pass
    else:
        print count
 
output
1
2
3
4
6
7
8
9  

 

Continue returns the control to the beginning of the while loop.. The continue statement rejects all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop.

count=0
while (count<9):
   count=count+1
   if count>5:
       continue
   print count

output
1
2
3
4
5




Wednesday, July 13, 2016

How to pratically learn python from zero: chapter two basics

First, to learn some basic concepts etc, you need a good tutorial, like below:

http://www.tutorialspoint.com/python/


Like many programming language, python uses some computer command to let computer finish some work for ppl. The work can be some computing work, can be software development.

To finish the work, one needs to learn how Python denote numbers, strings, vectors etc. Or in other words what kind of data structures python has.

Python use variable to denote different types of data.

It has several data types:

1. Number

counter=5

Assign 5 to counter. After that, once we refer ti counter, we mean a variable with value 5. 


2.String

string1="Alice"

Put the letters, numbers etc in a single or double quote, and assign to a variable. This variable will have a value in the quote.

Python's single quote, double quote and triple quotes have some different usages.

Here is an article talking about the three quotes:

http://faculty.tarleton.edu/agapie/documents/cs102_intro/lab01_gettingstarted_python2.pdf


3.List

List is like a vector in Python. It put a list of data into a "[]".

The elements in a list can be anything, numbers, strings etc.

list1=[1,2,3,'ak','oop',99]

We can add, remove elements from list. And we can iterate on a list.

add element:

cc="aa"
list1.append(cc)

remove element:

list1.remove('ak')



4.Tuple

Tuple is something included in a "()". And once we create a tuple. We can not alter it like list.

tuple1=(1,2,"wi")


5.Dictionary (hash table in Python)

Dictionary is quoted in "{}". It is some pairs of keys and values. And the keys are unique in a dictionary. I.e. the dictionary's keys can not have duplicates. Otherwise, you will have some error. And each key can have anything as the value, including the list etc.


Dict={"Name":"Alice", "Age": 7, "Height": "6"}

And we can refer to the values of the keys in a dictionary like this:

print Dict['Name']

And the values in a dictionary can be changed.



And you can set up a dictionary by  starting from a empty dictionary.

dic2={}

dic2["game name"]="football"
dic2["number of ppl"]=22
...

And then you can set up a dictionary from an empty dictionary.




Dictionary is a very powerful data type.  It is very useful. And if you analyze some messy data, you will use it a lot maybe.

There is another data type in python. It is called set. It is a list of elements. And the elements are all unique. So we can use set to calculate/get the unique elements in a list.




Operators in Python"

One also needs to know how python do the calculations, +,-,*,/. And it has a modular arithmetic "%".  The modular arithmetic may be different for positive and negative numbers.

The results of the dividing will be determined by the signs of both numbers. If the signs of the both numbers are same, then the results will be positive, otherwise it will be negative.

The results of the modular arithmetic will be determined by the signs of second numbers. If the sign of the second numbers is positive , then the result will be positive, otherwise it will be negative.

And python also has the operator like power. "**".



There are some other operators in Python too. Like the comparison operator, bitwise operators etc.

Sunday, June 26, 2016

How to practically learn Python starting from zero: chapter one set up environment

Python is a computer programming language. It is concise and not difficult to learn. If you want to learn a programming language well, besides reading tutorials, you need to 1. practice (like some small problems in a book, or some projects) , because doing programming is like finishing a craft project, you can learn it almost only by doing some craft projects yourself. 2. read other ppl's code. You can have one github account and put your code their and read other ppl's code there.

To use Python, one needs to have a platform/ OS.  It can be linux, Mac, windows. My experience is that Linux is better or equal to Mac, and they are both better than windows. Mac itself has a linux  terminal which is a plus.

Why linux is better than Windows for Python?  When you are doing python programming, quite often, you need to install additional packages for your Python. If you do it on windows, it is usually some pain in ass especially when the installing package is not exe file, is a zip file, you need to download the file, put it into a suitable directory and go to cmd window etc. And it sometimes fails. But, if you have a linux system and you finish all the programming on your terminal, to install a python package is just a command line. If you do not have Linux, you can install one using the following method on your PC:

http://easyprog99.blogspot.com/2016/04/one-way-to-install-linux-on-your-pc.html

And then install Python on ubuntu:

http://heliumhq.com/docs/installing_python_2.7.5_on_ubuntu

Then install an editor, emacs, or vim on your ubuntu:

http://askubuntu.com/questions/297170/how-to-install-emacs-24-3-on-ubuntu


I think it will take less than 1 hour.

You can test it by writing a simple Python program:

type 'emacs hello.py' to open a file
type in a hello word program:


print 'Hello World!'

ctrl x, ctrl c to close the file, you will be asked if you need to save the change, type 'y'.

To run it, type 'python hello.py', then 'Hello World' will show on your linux screen



On windows, there are two IDE, I would recommend:

1. Anaconda. you can use Anaconda to install your Python packages.  And run your programming on Anaconda. Otherwise, you will face some pain.

http://easyprog99.blogspot.com/2016/04/how-to-install-python-zip-package-on.html


And under Anaconda, there is an IDE called Spyder. After you install Anaconda, you will see it on your computer. It has such logo:



One advantage of using Anaconda is that it usually won't cause problems when you try to install additional packages on your computer even when the firewall of your computer is on.

2. PyCharm.  PyCharm is an IDE developed by  JetBrains. That company has IDEs for C++, Java etc.


https://www.jetbrains.com/pycharm/download/#section=windows

PyCharm has two versions, professional and community versions. Community version is free. Professional version is not free.  But sometimes when the firewall of your computer is on, it will cause problems when installing additional packages on the PyCharm. 

Thursday, June 23, 2016

About this pointer in c++

this refers to the current object.
The keyword this identifies a special type of pointer. Suppose that you create an object named x of class A, and class A has a non-static member function f(). If you call the function x.f(), the keyword this in the body of f() stores the address of x.

http://stackoverflow.com/questions/16492736/what-is-the-this-pointer


R is not a simple programming language, and it does better on reading excel files than python

R is not a simple programming language, and it does better on reading excel files than python . tried to read excel files to python and R. i...