Link to home
Start Free TrialLog in
Avatar of enthuguy
enthuguyFlag for Australia

asked on

python convert currency

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
ASKER CERTIFIED SOLUTION
Avatar of Kimputer
Kimputer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of enthuguy

ASKER

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']))
Avatar of Kimputer
Kimputer

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.