2

How should I format the following code as per the PEP-8 guidelines? I don't see examples for something like this. Or is there no guideline for this? Most questions on SO ask about splitting long conditionals or line continuation.

def send_notification(version, device_type):
    reg_ids = UDR.objects.filter(device_type=device_type).values_list('id', 'device_type', 'registration_id')

    if not reg_ids:
        logger.debug("No notifications to send")

Should it be formatted as:

def send_notification(version, device_type):
    reg_ids = UDR.objects.filter(
        device_type=device_type).values_list('id',
            'device_type', 'registration_id')

    if not reg_ids:
        logger.debug("No notifications to send")

Or as this:

def send_notification(version, device_type):
    reg_ids = UDR.objects.filter(device_type=device_type)\
                         .values_list('id',
                                      'device_type',
                                      'registration_id')

    if not reg_ids:
        logger.debug("No notifications to send")

Or something else altogether?

Divick
  • 1,213
  • 1
  • 20
  • 44
  • In case it helps anyone, autopep8 helps you format your code so that it is compliant with pep8 and is quite good to format your code in place. – Divick Dec 17 '15 at 02:26

1 Answers1

0

You can take some guidance form the following URL https://www.python.org/dev/peps/pep-0008/#code-lay-out

Just give it a try and do ask if you don't understand.

Abhi
  • 442
  • 1
  • 10
  • 24