python convert currency

enthuguy
enthuguy used Ask the Experts™
on
Hi Python experts,
Trying to convert an amount from USD to AUD

I tried below using interactive python and it worked

pip install --user currencyconverter

Open in new window


$ python
Python 2.7.5 (default, Aug  7 2019, 00:51:29)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2

>>> from currency_converter import CurrencyConverter
>>> c = CurrencyConverter()
>>> c.convert(100, 'USD', 'AUD')
146.9260630134513

Open in new window


However, trying to incorporate this into a python file but getting an error

convert.py
#!/usr/bin/env python3

import argparse
import boto3
import datetime
from currency_converter import CurrencyConverter

Open in new window


Traceback (most recent call last):
  File "/usr/local/bin/aws_cost_explorer.py", line 6, in <module>
    import CurrencyConverter
ImportError: No module named CurrencyConverter


please help
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
#!/usr/bin/env python
or
#!/usr/bin/env python2.7

Author

Commented:
Thanks for your quick help 2.7 helped.

any suggestion on this one please. trying to convert amount value. how to use convert ?

print(dtemplate.format(result_by_time['TimePeriod']['Start'], group['Keys'][0],  group['Keys'][1], float(amount), unit,  result_by_time['Estimated']))

Commented:
print(dtemplate.format(result_by_time['TimePeriod']['Start'], group['Keys'][0],  group['Keys'][1], c.convert(float(amount), 'USD', 'AUD'), unit,  result_by_time['Estimated']))

assuming c.convert takes in float and returns float.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial