How to place several "import ...." lines in one .py file?

fl rxjwg98 at gmail.com
Thu Jul 24 16:25:02 EDT 2014


Hi,

I have seen several kinds of module import examples, but most of the programs are
small and less content. They only have one or two module import.

I'll use the following modules in a small project. I would like to know whether
it is appropriate to put all of them at the file header, like this:



import pandas as pd
import numpy as np
import sci
import matplotlib.pyplot as plt
from pandas import DataFrame




Because some modules are used only at the beginning or the end, does it recommend
to separate to place the import lines just before the associated function lines.




import pandas as pd

.
..
...
import numpy as np

.
...
.....
import sci
..
.....
...
import matplotlib.pyplot as plt
from pandas import DataFrame



Or, it recommends to have separate files for each main functionality, such as
input, process and output (plot etc.)?



Thanks,



More information about the Python-list mailing list