systemctl (centos7)

  • 启动服务:
    systemctl start x.service
    
  • 关闭服务:
    systemctl stop x.service
    
  • 重启服务:
    systemctl restart x.service
    
  • 查看服务状态:
    systemctl status x.service
    
  • 开机启动服务:
    systemctl enable x.service
    
  • 开机不启动服务:
    systemctl disable x.service
    
  • 查看所有服务:
    systemctl list-units --type=service 
    

ntpdate

  • 更新服务器时间
    ntpdate -u ntp.api.bz
    

    ntp.api.bz: NTP 服务器(上海)

tuple

Tuples are immutable sequences.

tuple([iterable])

The constructor builds a tuple whose items are the same and
in the same order as iterable‘s items.

iterable may be a sequence,
a container that supports iteration, or an iterable object.

If iterable is already a tuple, it is returned unchanged.

  • Empty tuple: (), tuple()
  • Singleton tuple: 'a',, (‘a’,)
  • Multiple elements tuple: 'a', 0, ('a', 0), tuple(iterable)
  • t.count(x)

    return number of occurrences of x, if no x in the tuple
    a 0 value will be returned.

  • t.index(x, start=None, stop=None)

    Return first index of x. Raises ValueError if the x is not present.

class tuple(object):
    """
    tuple() -> empty tuple
    tuple(iterable) -> tuple initialized from iterable's items

    If the argument is a tuple, the return value is the same object.
    """
    def count(self, value): # real signature unknown; restored from __doc__
        """ T.count(value) -> integer -- return number of occurrences of value """
        return 0

    def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
        """
        T.index(value, [start, [stop]]) -> integer -- return first index of value.
        Raises ValueError if the value is not present.
        """
        return 0

    def __add__(self, *args, **kwargs): # real signature unknown
        """ Return self+value. """
        pass

    def __contains__(self, *args, **kwargs): # real signature unknown
        """ Return key in self. """
        pass

    def __eq__(self, *args, **kwargs): # real signature unknown
        """ Return self==value. """
        pass

    def __getattribute__(self, *args, **kwargs): # real signature unknown
        """ Return getattr(self, name). """
        pass

    def __getitem__(self, *args, **kwargs): # real signature unknown
        """ Return self[key]. """
        pass

    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        pass

    def __ge__(self, *args, **kwargs): # real signature unknown
        """ Return self>=value. """
        pass

    def __gt__(self, *args, **kwargs): # real signature unknown
        """ Return self>value. """
        pass

    def __hash__(self, *args, **kwargs): # real signature unknown
        """ Return hash(self). """
        pass

    def __init__(self, seq=()): # known special case of tuple.__init__
        """
        tuple() -> empty tuple
        tuple(iterable) -> tuple initialized from iterable's items

        If the argument is a tuple, the return value is the same object.
        # (copied from class doc)
        """
        pass

    def __iter__(self, *args, **kwargs): # real signature unknown
        """ Implement iter(self). """
        pass

    def __len__(self, *args, **kwargs): # real signature unknown
        """ Return len(self). """
        pass

    def __le__(self, *args, **kwargs): # real signature unknown
        """ Return self<=value. """
        pass

    def __lt__(self, *args, **kwargs): # real signature unknown
        """ Return self<value. """
        pass

    def __mul__(self, *args, **kwargs): # real signature unknown
        """ Return self*value.n """
        pass

    @staticmethod # known case of __new__
    def __new__(*args, **kwargs): # real signature unknown
        """ Create and return a new object.  See help(type) for accurate signature. """
        pass

    def __ne__(self, *args, **kwargs): # real signature unknown
        """ Return self!=value. """
        pass

    def __repr__(self, *args, **kwargs): # real signature unknown
        """ Return repr(self). """
        pass

    def __rmul__(self, *args, **kwargs): # real signature unknown
        """ Return self*value. """
        pass

list

  • list() new empty list
  • list(iterable) new list initialized from iterable’s items

The constructor builds a list whose items are the same and
in the same order as iterable’s items.

iterable may be either a sequence, a container that supports iteration,
or an iterator object. If iterable is already a list, a copy is made and returned,
similar to iterable[:]. e.g. list('abc') => ['a', 'b', 'c'],
list(range(2)) => [0, 1], list([0, 1]) => [0, 1].

Create

  • l.copy() # New in Python3

    Return a shallow copy of l.

  • l.append(p_object)

    Append object to the end of l.

  • l.insert(index, p_object)

    Insert object before index.

  • l.extend(iterable)

    Extend list by appending elements from iterable.

Delete

  • l.pop([index])

    Remove and return item at index (default last).
    Raises IndexError if list is empty or index is out of range.

  • l.remove(value)

    Remove first occurrence of value.
    Raises ValueError if the value is not present.

  • l.clear() # New in Python3

    Return a shallow copy of l.

Retrieve

  • l.count(value)

    Return number of occurrences of value.

  • l.index(value, [start[, stop]])

    Return first index of value.

Update

  • l.reverse()

Reverse IN PLACE. e.g.

l = [0, 1, 2]
l.reverse()   # No list return, but reverse in place
print(l)
[2, 1, 0]
  • l.sort([key, reverse])

Sorts the list l in place.

sort() accepts two arguments that can only be passed by keyword (keyword-only arguments).

Error: l.sort(lambda x: x == 2), l.sort(lambda x: x == 2, True)

True: l.sort(key=lambda x: x == 2), l.sort(key=lambda x: x == 2, reverse=True)

key, specifies a function of one argument that is used to extract a
comparision key from each list element (e.g. key=str.lower).

The smaller of the key function return value, the corresponding item is more forward.
And the True indicate int 1, False indicate int 0.

l = [5, 1, 2, 4, 0]
l.sort(key=lambda x: x == 2)
print(l)
[5, 1, 4, 0, 2]   # 2 => True(1); others => False(0)
l.sort(key=lambda x: x)
print(l)
[0, 1, 2, 4, 5]
class list(object):
    """
    list() -> new empty list
    list(iterable) -> new list initialized from iterable's items
    """
    def append(self, p_object):
        """ L.append(object) -> None -- append object to end """
        pass

    def clear(self): # New in Python3
        """ L.clear() -> None -- remove all items from L """
        pass

    def copy(self): # New in Python3
        """ L.copy() -> list -- a shallow copy of L """
        return []

    def count(self, value):
        """ L.count(value) -> integer -- return number of occurrences of value """
        return 0

    def extend(self, iterable):
        """ L.extend(iterable) -> None -- extend list by appending elements from the iterable """
        pass

    def index(self, value, start=None, stop=None):
        """
        L.index(value, [start, [stop]]) -> integer -- return first index of value.
        Raises ValueError if the value is not present.
        """
        return 0

    def insert(self, index, p_object):
        """ L.insert(index, object) -- insert object before index """
        pass

    def pop(self, index=None):
        """
        L.pop([index]) -> item -- remove and return item at index (default last).
        Raises IndexError if list is empty or index is out of range.
        """
        pass

    def remove(self, value):
        """
        L.remove(value) -> None -- remove first occurrence of value.
        Raises ValueError if the value is not present.
        """
        pass

    def reverse(self):
        """ L.reverse() -- reverse *IN PLACE* """
        pass

    def sort(self, key=None, reverse=False):
        """ L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """
        pass

    def __add__(self, *args, **kwargs):
        """ Return self+value. """
        pass

    def __contains__(self, *args, **kwargs):
        """ Return key in self. """
        pass

    def __delitem__(self, *args, **kwargs):
        """ Delete self[key]. """
        pass

    def __eq__(self, *args, **kwargs):
        """ Return self==value. """
        pass

    def __getattribute__(self, *args, **kwargs):
        """ Return getattr(self, name). """
        pass

    def __getitem__(self, y):
        """ x.__getitem__(y) <==> x[y] """
        pass

    def __ge__(self, *args, **kwargs):
        """ Return self>=value. """
        pass

    def __gt__(self, *args, **kwargs):
        """ Return self>value. """
        pass

    def __iadd__(self, *args, **kwargs):
        """ Implement self+=value. """
        pass

    def __imul__(self, *args, **kwargs):
        """ Implement self*=value. """
        pass

    def __init__(self, seq=()):
        """
        list() -> new empty list
        list(iterable) -> new list initialized from iterable's items
        # (copied from class doc)
        """
        pass

    def __iter__(self, *args, **kwargs):
        """ Implement iter(self). """
        pass

    def __len__(self, *args, **kwargs):
        """ Return len(self). """
        pass

    def __le__(self, *args, **kwargs):
        """ Return self<=value. """
        pass

    def __lt__(self, *args, **kwargs):
        """ Return self<value. """
        pass

    def __mul__(self, *args, **kwargs):
        """ Return self*value.n """
        pass

    @staticmethod
    def __new__(*args, **kwargs):
        """ Create and return a new object.  See help(type) for accurate signature. """
        pass

    def __ne__(self, *args, **kwargs):
        """ Return self!=value. """
        pass

    def __repr__(self, *args, **kwargs):
        """ Return repr(self). """
        pass

    def __reversed__(self):
        """ L.__reversed__() -- return a reverse iterator over the list """
        pass

    def __rmul__(self, *args, **kwargs):
        """ Return self*value. """
        pass

    def __setitem__(self, *args, **kwargs):
        """ Set self[key] to value. """
        pass

    def __sizeof__(self):
        """ L.__sizeof__() -- size of L in memory, in bytes """
        pass

    __hash__ = None


set

A set object is an unordered collection of distinct hashable objects.

Like other collections, sets support x in set, len(set), and for x in set. Being an unordered collection, sets do not record element position or order of insertion. Accordingly, sets do not support indexing, slicing, or other sequence-like behavior.

There are currently two built-in set types, set and frozenset.

  • set([iterable]) – Return a set. The elements of a set must be hashable, bue the set type itself is mutable. The contents can be changed using methods like add() and remove(). Since set type is mutable, it has no hash value and cannot be used as either a dictionary key or and element of another set.

    Non-empty sets(not frozensets) also can be created by placing a comma-separated list of elements within braces, for example: {'jack', 'lizs'}, in addition to the set constructor.

  • frozenset([iterable]) – Return a frozenset. The elements of frozenset must be hashable and the frozenset type is immutable and hashable. its contents cannot be altered after it is created, it can therefore be used as a dictionary key or as an element of another set.

  • len(S) # set/frozenset

    Return the member of elements in set s (cardinality of s).

  • x in s # set/frozenset

  • x not in s # set/frozenset

  • isdisjoint(other) # set/frozenset

    Return True if the set has no elements in common with other.
    Sets are disjoint if and only if their intersection is the empty set.

  • issubset(other)

  • set <= other

    Test whether every element in set is in other.

  • set < other

    Test whether the set is a proper subset of other, that is set <= other and set != other.

  • issuperset(other)

  • set >= other

    Test whether every element in other is in the set.

  • set > other

    Test whether the set is a proper superset of other, that is, set >= other and set != other.

  • s.union(*other)

  • set | other

    Return a new set with elements from the set and all others.

  • s.intersection(*other)

  • set & other

    Return a new set with elements common to the set and all others.

  • s.difference(*others)

  • set – other

    Return a new set with elements in the set that are not in the others.

  • s.symmetric_difference(other)

  • set ^ other

    Return a new set with elements in either the set or other but not both.

  • s.copy()

    Return a new set with a shallow copy of s.

Note, the non-operator versions of union(), intersection(), difference(),
and symmetric_difference(), issubset(), and issupperset() methods will
accept any iterable as an argument. In contrast, their operator based counterparts
require their arguments to be sets.

Instance of set are compared to instances of frozenset based on their members.
e.g. set('abc') == frozenset('abc') return True and so does set('abc') in set([frozenset('abc')])

Binary operations that mix set instances with frozenset return the type of first operand.
e.g. frozenset('ab') | set('bc') returns an instance of frozenset

The following table lists operations available for set that do not apply to immutable instances of frozenset:

  • s.update(*other)
  • set |= other

    Update the set, adding elements from all others.

  • s.intersection_update(*other)

  • set &= other

    Update the set, keeping only elements found in it and all others.

  • s.difference_update(*other)

  • set -= other

    Update the set, removing the elements found in others.

  • s.symmetric_difference_update(*other)

  • set ^= other

    Update the set, keeping only elements found in either set, but not in both.

  • s.add(elem) # set

    Add element elem to the set.

  • s.discard(elem)

    Remove element elem from the set if it is present.

  • s.remove(elem)

    Remove element elem from the set. Raises KeyError if elem is not contained in the set.

  • s.pop()

    Remove and return an arbitrary element from the set. Raises KeyError if the set is empty.

  • s.clear()

    Remove all elements from the set.

Note, the non-operator versions of update(), intersection_update(),
difference_update(), symmetric_difference_update() methods will accept
any iterable as an argument.