2014-07-14 19 views
1

這是什麼,我想用我的代碼來完成:confparse說,IP地址沒找到作爲文件或目錄

properties(IPADDR='192.168.0.1', NETMASK='255.255.255.0').apply_to('/path/to/ifcfg-eth0') 

然而,它指出該IP地址沒有找到作爲文件或目錄。但從文檔中我們可以看到這是正確的格式。

SEE:http://code.google.com/p/confparse/

CODE BELOW:

def writestaticConf(nic, ipa, netm): 
    """ Write conf file """ 
    whichnic = '/etc/sysconfig/network-scripts/ifcfg-' + nic 
    print whichnic 
    ip = "IPADDR=" + ipa 
    mask = "NETMASK=" + netm 
    print ip + " " + mask 
    properties(ip, mask).apply_to(whichnic) 

TRACEBACK BELOW

In [45]: writestaticConf('eth0','192.168.0.1', '255.255.255.0') 
/etc/sysconfig/network-scripts/ifcfg-eth0 
IPADDR=192.168.0.1 NETMASK=255.255.255.0 
--------------------------------------------------------------------------- 
IOError         Traceback (most recent call last) 
<ipython-input-45-00917222fac3> in <module>() 
----> 1 writestaticConf('eth0','192.168.0.1', '255.255.255.0') 

<ipython-input-44-7af6f7537082> in writestaticConf(nic, ipa, netm) 
     6  mask = "NETMASK=" + netm 
     7  print ip + " " + mask 
----> 8  properties(ip, mask).apply_to(whichnic) 
     9  #w.apply_to(whichnic) 

/root/.virtualenvs/teknasportal/lib/python2.7/site-packages/confparse-1.0a1-py2.7.egg/confparse.py in __init__(self, _fileordict, _order, **kwargs) 
    123   if isinstance(_fileordict, str) or isinstance(_fileordict, list): 
    124    self.template=_fileordict 
--> 125    self.read(_fileordict) 
    126 
    127   elif hasattr(_fileordict, '__setitem__'): 

/root/.virtualenvs/teknasportal/lib/python2.7/site-packages/confparse-1.0a1-py2.7.egg/confparse.py in read(self, filenames) 
    309 
    310   if isinstance(filenames, basestring): 
--> 311    self._read(file(filenames), filenames) 
    312    self.template=filenames 
    313 

IOError: [Errno 2] No such file or directory: 'IPADDR=192.168.0.1' 
+2

有一個正當理由不能在問題標題中使用'問題'。不要通過拼寫錯誤來顛覆過濾器,而應該拿出更好的標題。 –

+0

你會在家裏感到驚訝,許多人都這麼做。如果你真的拼錯'問題',那麼你有我的道歉。然而,*這裏的每一個問題都是*,因爲*有人有問題,所以說你有一個問題是說明顯的。 snowandotherjoys'編輯使你的標題對查看問題列表的任何人都更有用。下次考慮到我們每天會在這裏得到1000個問題,並且不得不面對來自許多問題提問者的無視最低標準的問題,因爲我們每天都會受到歡迎。 –

+0

我沒有說我有問題。我在問包裝是否有問題。即錯誤。 – DataUnixVerse

回答

2
properties('IPADDR=192.168.0.1', 'NETMASK=255.255.255.0') 

是不一樣的

properties(IPADDR='192.168.0.1', NETMASK='255.255.255.0') 

如果您想使用關鍵字參數,請使用關鍵字參數!不要將'IPADDR='附加到字符串本身。

properties(IPADDR=ip, NETMASK=mask) 
+0

你是對的。不需要!我是編程新手。但謝謝你的幫助。 – DataUnixVerse