Doubts regarding the PEP8

Asked

Viewed 112 times

1

I read the PEP8 but did not understand very well when using 2 blank spaces.

I must use 2 spaces to separate a section of imports from another section?

What sections a Python file normally displays?

I must have a file with all my classes or a file for each class as in other languages?

import os
import random
import threading

import pygame

from classes import Carta


def main():
    pass


main()

Is that correct? Two spaces between the imports and the function main and 2 more between the function main and the call to her?

1 answer

2


Not two spaces, two blank lines.

PEP8 does not talk about the separation of imports, but I guess it only makes sense to separate all of them from the rest of the code, so it would look like this:

import os
import random
import threading
import pygame
from classes import Carta

def main():
    pass

main()

I put in the Github for future reference.

But maybe you can leave a line after imports. I don’t see the same advantage of separating as much as it is between classes and loose functions.

I don’t really like the idea of sections. But it is common to have imports, loose functions, classes and even loose code that should be avoided.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.