I researched and went through different projects that have been done to scan barcodes. The most useful one I found was 6 lines of Python code that is given bellow. The code was found on a blog that used the example of scanning books. It can be found at this link.
Code:
Other interesting code for scanning barcodes can be found at this link.