假設我有一個模塊,名爲設備其中包含一個名爲ConfigureDevice的類。讓我們也說我有一個叫做comports的模塊,它定義了我的com類在一個叫做ComPorts(enum in C)的類中。何處導入模塊
現在,假設ConfigureDevice的構造函數接受一個名爲comPorts的參數。問題是,我應該在設備模塊的開頭導入comports,還是應該創建ConfigureDevice這個導入?
所以,應進口相稱發生在這裏:
# device module
import serialwriter
import comports
class ConfigureDevice:
def __init__(self, comPort):
self.serialWriter = serialwriter.SerialWriter(comPort)
或者我應該導入它在創建ConfigureDevice,這樣的代碼:
import device
import comports
...
device.ConfigureDevice(comports.ComPorts.COM_1)
[Python import coding style](http://stackoverflow.com/questions/477096/python-import-coding-style) – DhruvPathak