Showing posts with label mixed tabs and spaces. Show all posts
Showing posts with label mixed tabs and spaces. Show all posts

Tuesday, 2 September 2014

Use of "l" as long integer identifier :: Pylint :: W0332


Error:

lowercase-l-suffix, Use of "l" as long integer identifier

Description

Raised by pylint, Use of “l” as long integer identifier Used when a lower case “l” is used to mark a long integer. You should use a upper case “L” since the letter “l” looks too much like the digit “1”

Example(s)

Given sample of code describe basic divide function, it takes two arguments a and b. We have simple divided first argument with second and returned result. We have calculated division in case of inequality while constant 1 as long integer for equality case.

def divide(a, b):
    """
    function to take two arguments to divide first by second
    """
    try:
        if a != b:
            result = a/b
        else:
            result = 1l
    except ZeroDivisionError:
        result = 0
    return result



Solution(s)

This could be resolved using Capital "L" to represent long Integer.

Use "L"


def divide(a, b):
    """
    function to take two arguments to divide first by second
    """
    try:
        if a != b:
            result = a/b
        else:
            result = 1L
    except ZeroDivisionError:
        result = 0
    return result

old-ne-operator :: Pylint :: W0331


Error:

old-ne-operator, Use of the <> operator

Description

Raised by pylint, when old inequality operator <> is used. This error is not fatal but considered a bad practice and could result in unexpected behavior.

Example(s)

Given sample of code describe basic divide function, it takes two arguments a and b. We have simple divided first argument with second and returned result. We have calculated division in case of inequality while constant 1 for equality case.

def divide(a, b):
    """
    function to take two arguments to divide first by second
    """
    try:
        if a <> b:
            result = a/b
        else:
            result = 1
    except ZeroDivisionError:
        result = 0
    return result



Solution(s)

This could be resolved using standard != for testing not equal.

Use !=


def divide(a, b):
    """
    function to take two arguments to divide first by second
    """
    try:
        if a != b:
            result = a/b
        else:
            result = 1
    except ZeroDivisionError:
        result = 0
    return result



Monday, 1 September 2014

mixed-indentation :: Pylint :: W0312


Error:

Used when there are some mixed tabs and spaces in a module.

Found indentation with tabs instead of spaces
Found indentation with spaces instead of tabs

Description

Raised by pylint, when a mix of both spaces and tabs is used for indentation purpose. Precisely, when an indent is detected that is not consistent with the indent-string option. By default, indent-string is set to four spaces, the style of indentation recommended in PEP-8. This error is not fatal but considered a bad practice and could result in unexpected behavior.

Example(s)

Given sample of code describe basic divide function, it takes two arguments a and b. We have simple divided first argument with second and returned result. We have used spaces and tab both to represent  as single indentation

def divide(a, b):
        """
        function to take two arguments to divide first by second
        """
        try:
            result = a/b
        except ZeroDivisionError:
            result = 0
        return result


Solution(s)

PEP recommend four spaces to be used as indentation, So this could be resolved using standard four spaces for indentation.

Use Four spaces
Use four spaces for single indentation.

    def divide(a, b):
        """
        function to take two arguments to divide first by second
        """
        try:
            result = a/b
        except ZeroDivisionError:
            result = 0
        return result