Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Wondering if Python has free and reliable library to read Excel file, manipulate data and generate Excel file output, just like VBA did? My current problem is, the project has both Python and VBA code, I am trying to see if I can use single programming language to make it simple. Thanks.
Using Python 2.7.
regards,
Lin
I either use openpyxl or the pywin32 COM interface directly.
openpyxl is very fast as it manipulates data directly in the excel file on disk, where as the pywin32 com interface uses Excel itself, with the python code mimicking what VBA does.
The main difference between the two is that openpxl only gives you a subset of commands, so great for pulling data out of an excel file to use elsewhere or building a new excel file from existing data. However to get the full functionality you need to use the COM interface.
This site gives a good intro to using the COM interface. One thing to watch out for is the constants that are scattered throughout the COM interface calls. You generally need to find out those values yourself, you can start by looking here
Finally you can also take a look at IronPython which is a .NET implementation of python which gives a cleaner interface but isn't actually vanilla python (and not cross-platform), so maybe not what you want.
I would like to recommend openpyxl
I used it for creating basic Excel reports for business teams, and it has been a pleasure to use. :-)
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 months ago.
Improve this question
I'm trying to migrate some perl code to python and it uses Sleeypcat::DbXml 'simple' to get read access to a .dbxml file, creates a XmlManager, calls createQueryContext, openContainer and query to get an XmlValue. I have found https://pypi.org/project/berkeleydb/ to support the Berkeley DB in general, but it has no mention of this XML layer. Is there an existing API I can use in python 3?
Berkeley dbxml does come with a Pyhon bindings. I ended up having to make modifications to the SWIG interface files to get it to run with Python3. If you are interested in building for a recent Python, you will need to make some modifications to the Python interface file. Specifically, you have to
redefine PYSTR_* macros to use unicode strings
make changes to the initialization code to return the module
update the Python 3 iterator code to use __next__ via a %rename pragma
potentially add code for missing objects an changed interfaces, e.g. I added an XmlResultsIterator, and added som code to XmlManager to let me reindex containers.
You then need to regenerate the swig interface and recompile the module. I don't know StackOverflow's policy on posting patches, but if it's allowed I'd be happy to post the patches that I created for dbxml 6.1.4 and Python 3.9 for you. Getting it all compiled is a little bit of work, but very doable.
Berkeley DB and Berkeley DB XML are two different products. My python bindings (legacy "bsddb3" and current "berkeleydb") only interface with Berkeley DB.
I am not aware of any Python bindings for Berkeley DB XML.
I am a freelance with commercial contracts, if that option would be useful to you.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am interested in doing some snail mail based surveys but I am looking for quick ways to digitize the surveys they send back.
So if I had a question and 5 boxes beneath it where you would indicate your opinion by checking the appropriate box, does anything exist where I could scan it and run it through a piece of software that spit out the responses.
Edit clarification:
I am inquiring about what I need to do after the paper has been digitized. I want to write some code that looks at an image file and recognizes which box has been marked in and outputs a representation of the respondents answers.
I would be looking at a page scanned from a desktop scanner or something similar.
From what i see you don't really need ICR (intelligent character recognition, used for handwritten and handprinted texts), but what you need is OMR - optical mark recognition (capturing human-marked data from document forms such as surveys and tests).
The bad news is you would hardly find an opensource library for python. But there's a solution - you can use a cloud SDK, it's a website that let you upload an image and send you back an OCR'ed data. Try www.ocrsdk.com, it is a cloud based OCR SDK recently launched by ABBYY. It's now in closed beta so it's completely free to use.
It has both ICR and OMR api methods and a set of python code samples.
I don't really see what this has to do with python, unless of course you've already digitized the results and are now looking to tally up the results. It sounds like you still need to scan the results in and as far as I know, python doesn't have any direct capabilities of doing something like that. You're going to have to get your hands on a scanner first, and only then can you use python to read through the data.
The SDAPS project (repo) might be worth a look. It may not handle arbitrary scanned images, as it seems to expect an ODT or LaTeX document at the beginning of the process.
Overview
SDAPS is an open source (GPLv3, LPPL) optical mark recognition (OMR) program. It is
written in python and has an integrated workflow with both LibreOffice and LaTeX to
create questionnaires.
Workflow
With SDAPS you create the questionnaire using either LibreOffice or LaTeX. After this
some processing is done to collect the information about the survey (questions, and
answers) and a printable PDF is created. The filled out questionnaires only need to be
scanned in (example). SDAPS will do the optical mark recognition and can create a PDF
report (example) or export the data. Optionally it is possible to manually correct the
results using a graphical user interface.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm writing end-to-end tests for my tool, which is written in Python. The tool reads a file as input. I want to test its exit code, and its output.
This is a fairly common idiom, and I've seen it done in several ways. In the PHP project, each test is a file, and has lines like: INPUT:, EXPECTED:, EXPECTED_REGEX:, etc. In my own phc project, each file is a normal source file, but with a comment added to the top, which includes keywords like EXPECTED. I think I had copied that off gcc which uses a much more complex tool written in tcl.
Are there frameworks, libraries, etc, that do this in Python? It should:
read the source file
parse special keywords (or similar) corresponding to expected output, exit code, words/regexes it expects to find or not find,
check that the output is correct.
While it doesn't seem hard in theory, I recall lots of edge-cases (esp involving escaping) when implementing this before, and would rather not reinvent the wheel.
The robot framework might be helpful. It is a keyword driven functional testing tool implemented in python and can be extended with pythion or java.
see: http://robotframework.googlecode.com/svn/tags/robotframework-2.5.4/doc/userguide/RobotFrameworkUserGuide.html
There are a number of built in libraries that you might be able to apply to solve your problem, including a OperatingSystem library for working with files etc. and a Strings library for working with strings:
http://robotframework.googlecode.com/svn/tags/robotframework-2.5.4/doc/userguide/RobotFrameworkUserGuide.html#standard-libraries
There is also a http://pythonpaste.org/scripttest/ library by Ian Bicking.
Since the implementation of file io is system dependent, why not mock out the file reading and writing using StringIO:
http://docs.python.org/library/stringio.html
and then test the bulk of the logic (reading from a file, doing some stuff, writing to a file) in python?
Then, perhaps you could have one end to end test for basic sanity by having a separate python file call out to the script using the commands module or something similar where you are calling out to it as another process:
http://docs.python.org/library/commands.html
Using that you could get both the output, and the status.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I am looking to create a utility that validates Embedded (PPC or ARM) Linux *.dts (device tree source) or *.dtb (binary) files against an XML configuration file from another tool. So, I need to parse the dts or dtb files. I would really like to do this with Python. Does anyone know of a Python library or tool out there that parses dts or dtb files? A Python implementation of the device tree compiler (dtc) would be perfect, but I've not seen one yet.
It seems that the Zephyr project (a RTOS making use device trees) comes with a rather generic Python module dtlib to parse device tree source files. The module is part of the Zephyr source tree and stored in scripts/dts/dtlib.py.
Update December 2021
It seems that this got separated into its own repository available at https://github.com/zephyrproject-rtos/python-devicetree.
There is no python binding for libfdt (the device tree manipulation library shipped with dtc) yet, but it should be fairly straightforward to create one.
If you're interested in doing this, the Python docs have a bit about extending python using c modules: http://docs.python.org/release/2.6/extending/extending.html . The swig utility can be used to automatically create the Python-to-C interface, so you just end up writing a small swig configuration file.
If you do end up doing this, send the folks at devicetree-discuss#lists.ozlabs.org an email - we'd be keen to hear how you go!
libfdt is used to parse dtb file instead of device tree file (dts/dtsi), so it might not help to read libfdt, and you can't simply use SWIG to create a python binding of existing device parser.
Since dtc uses lex/yacc as the parsing tool and its syntax definition is available in kernel, I suggest you could use lex/yacc in python ([PLY]:http://www.dabeaz.com/ply/) to compose your own device tree parser.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am looking for a good config file library for c that is not xml. Optimally I would really like one that also has python bindings. The best option I have come up with is to use a JSON library in both c and python. What would you recommend, or what method of reading/writing configuration settings do you prefer?
YaML :)
If you're not married to Python, try Lua. It was originally designed for configuration.
You could use a pure python solution like ConfigObj and then simply use the CPython API to query for settings. This assumes that your application embeds Python. If it doesn't, and if you are shipping Python anyway, it might make sense to just embed it. Your C .exe won't get that much bigger if it's a dynamic link, and you will have all the flexibility of Python at your disposal.
Despite being hated by techies and disowned by Microsoft, INI files are actually quite popular with users, as they are easy to understand and edit. They are also very simple to write parsers for, should your libraries not already support them.