alxwrd / coinhandler Goto Github PK
View Code? Open in Web Editor NEW:moneybag: A Python module to handle interacting with coins
License: MIT License
:moneybag: A Python module to handle interacting with coins
License: MIT License
From the README:
When using the Coin factory class, a valid coin value should be used. Not doing so can create undesirable Coin objects.
>>> coin = Coin(23) OnePence(23) # Use a CoinCollection instead! >>> CoinCollection.from_value(23) CoinCollection(TwentyPence(1), TwoPence(1), OnePence(1))
Re-thinking this I think it should be invalid to enter a state where an undesirable coin is about to be created (OnePence(23)
).
I feel the correct way to handle this is to either raise an InvalidCoin
exception. If a Coin
has an .amount
greater than 1, it's invalid.
Coins can be created by subclassing Coin
, but once created they can't be removed.
Currently, the only valid coin set is GBP. It would be good to be able to use different currencies.
The file structure could become
coinhandler/
├── __init__.py
├── coinhandler.py
├── collections.py
└── coins/
├── __init__.py
├── gbp.py
├── usd.py
└── etc..
With usage being
import coinhandler
from coinhandler.coins import gbp # Required, if not all coins will be `Coin`
__init__.py
for coins/
will contain the base definition of Coin
.
This is related to #2, with the added thought being it'd be nice to be able to remove a whole module.
coinhandler.Coin.remove_subcoins(gbp)
This library seems like a cool idea, looking good!
I jumped into the code and noticed there's a file called collections.py
, but 'collections' is already a thing in Python:
This might cause namespacey problems, and could slightly hinder readability - I saw collections
was being imported in coinhandler.py
and briefly thought it was referring to Python's own collections
.
Might be worth renaming this to something more specific, although it's not really a problem if you want to keep the name the same
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.