Category archives: Notes

RSS feed of Notes

Python list

Python list

a.Method for creating a list

     1.create list
        >>> a=["python",25,89.9]
        >>> a
     2.list index   
        >>> a=["python",25,89.9]
        >>> a[0]
        >>> a[1]
        >>> a[2]
        >>> a[-1]
        #get the index ...

Continue reading

Between the characters and numbers in Python is how to compare the size?

Between the characters and numbers in Python is how to compare the size?

1. any two objects can be compared

2. The same type of objects (instances), if it is digital type (int/float/long/complex), in accordance with the simple size to compare; if is non numeric type and class (type) definition of the ...

Continue reading

Python set

1.Method for creating a set

 2)s=set("python") or s=set([1,"python"])
   ps. set to list: 
       list to set(can remove duplicate elements from the set):
       Create an immutable set in "frozenset"

2.Common method of set

    b ...

Continue reading

Implementation of Case Swithch syntax in Python

Python itself has no switch statement, there are 3 kinds of Solutions:

1.use dictionary

cases = {
           case1: do_some_stuff1,
           case2: do_some_stuff2,
           caseN: do_some_stuffN,
cases.get(var, do_default_stuff)()

2.use lambda

result = {
  'a': lambda x: x * 5,
  'b': lambda x: x + 7,
  'c': lambda x: x - 2

3.Beck Brian provides a class switch to ...

Continue reading

Python basic usage of pickle

Python pickle

import pickle

#dumps(object) :Object serialization
#print listb

#loads(string) :The object is restored, and the object type is restored to the original format.
#print listc

#dump(object,file) :To store objects in a file.
f1=file ...

Continue reading

Python basic grammar

python basic grammar

1.Constant and Variable

      import const
      print const.value

2.Number and string

   1)Single quotation mark
     eg. a='string'
   2)Double quotation marks
     eg. b="string"
   3)Three single quotation marks (output special characters)
     eg. c='''string ...

Continue reading

Python read and write files

Python read and write file

1.Python read and write file


print fr.readline()  
print fr.tell()

print fr.readlines()  
fw.write("===write line===")  
fw.close(),0) #The first parameter represents the number of bytes, after which a parameter represents the relative ...

Continue reading

Linux systemctl is the replacement for service and chkconfig

1.Enable a service to start automatically

1) chkconfig --level 3 SERVICENAME on (old command)    
2) systemctl enable SERVICENAME.service (new command)

2.Disable a service to start automatically

1) chkconfig --level 3 SERVICENAME off (old command)    
2) systemctl disable SERVICENAME.service (new command)

3.View service status(old command and old command)

1) service ...

Continue reading

Linux configure Mysql to allow remote access

The operation is very simple, on the 5 step, as follows:

1.login mysql :

>mysql -uroot -p;

2.Using mysql database:

>use mysql;

3.View user table :

>SELECT Host,User FROM user;
| host         | user | password                                  |
| localhost    | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
|  | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |

4.Update user table :

>UPDATE user SET Host = '%' WHERE User = 'root ...

Continue reading

Linux rpm related commands

RPM(RedHat Package Manager)

Binary package (Binary) as well as the source code package (Source) two. The binary package can be installed directly on the computer, and the source code package will be compiled and installed automatically by the RPM. Source code packages often use src.rpm as a suffix.

1.Common command combination:

-ivh ...

Continue reading