LoginSignup
3
0

More than 3 years have passed since last update.

DynamoDBとLambdaとPython3.7

Last updated at Posted at 2019-09-12
botoをrequirements.txtに含める必要はありません

Python3.xには標準で含まれている模様です。
わざわざ入れたらパッケージが45MBになり、コードが画面上で編集できなくなってしまいました。

→出典

Float types are not supported. Use Decimal types instead.

i = {
  'year': 2015,
  'title': 'The Big New Movie',
  'info': {
    'plot': "Everything happens all at once.",
    'rating': 24.1
  }
}

table.put_item(
  Item = i
)

ratingが24なら問題ないけど、24.1だとエラーになる。


i = {
  'year': 2015,
  'title': 'The Big New Movie',
  'info': {
    'plot': "Everything happens all at once.",
    'rating': decimal.Decimal('24.1')
  }
}

table.put_item(
  Item = i
)

シングルクォートがないと下記のエラーになる。ことがある。

  "errorMessage": "[<class 'decimal.Inexact'>, <class 'decimal.Rounded'>]",
  "errorType": "Inexact",
'rating': decimal.Decimal(5.0) ← エラーにならない
'rating': decimal.Decimal(5.1) ← エラー
'rating': decimal.Decimal(5.5) ← エラーにならない
'rating': decimal.Decimal(5.5555555) ← エラー
'rating': decimal.Decimal(5.6) ← エラー
'rating': decimal.Decimal(5.9) ← エラー
'rating': decimal.Decimal(24.1) ← エラー
'rating': decimal.Decimal(24.5) ← エラーにならない

なぜか0.5刻みのときだけセーフ。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0