I have seen many online examples with different ways of import
ing modules. I was wondering what the difference is, if it is in speed, accuracy, priority, or psychology.
The first, and most common is;
import sys
import os
import socket
import shutil
import threading
import urllib
import time
import zipfile
I understand the methodry, but this seems unnecessary when you can use, like I personally do;
import sys, os, socket, shutil, threading, urllib, time, zipfile
Less lines, less code, less headaches, at least in my opinion. However, the third one stumps me;
import sys, os, shutil
import threading
import zipfile
import socket, urllib
import time
What is the point or purpose of that method of importing? I would think that it would be inconvenient to mix the first two methods, as well as cluttered. It also seems like it would be slower than either method, or in worst case scenario, slower than both combined.
So, like I was wondering, what's the difference between the three?
Is there any logic in the third one, like a speed increase, or is it just for looks?
Functionally, they do the same thing. It's a style preference. Many people adhere to the PEP-8 style guidelines (ref: https://www.python.org/dev/peps/pep-0008/#imports) which state that imports should be on separate lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With