2015-09-27 18 views
-2

我收到語法錯誤:語法錯誤在Python兩種例如信息

'Starting: '.instance.id.' DNS{}:'.format(instance.dns.name) 

在運行博託Python API中顯示的實例信息

+0

你已經做了什麼來研究這個問題?什麼是你得到的_exact_錯誤? –

+2

我不能說我過分驚訝 - 你爲什麼認爲它可能工作? – jonrsharpe

回答

1

我懷疑你得到的錯誤是AttributeError: 'str' object has no attribute 'instance',這正在告訴你問題是什麼:'Starting: '是一個字符串,它沒有名爲instance的屬性。

最有可能的代碼需要是這樣的:

'Starting: ' + instance.id + ' DNS{}:'.format(instance.dns.name) 

,說的是:「開始的字符串‘開始:’,附加到實例ID,然後添加字符串」 DNS「,並附加實例ID的」name「屬性的值。

我不知道這是100%正確的,因爲我不知道instance的屬性是什麼,也不知道是否它具有id屬性,並且該id屬性是否具有name屬性。

+1

爲什麼要這樣混合串聯和'.format'? – jonrsharpe

+0

@jonrsharpe:因爲這似乎是OP試圖做的事情。這很糟糕,但我試圖對OP的代碼進行儘可能小的更改。 –