Python wrappers for PHP functions, when you just can't shake it.
If you're coming from PHP, you'll take a bit of time getting used to the new names or methods in Python. You could look up something like "python str_replace"
everytime you want to do so, or you could just save time and use php.str_replace('Hello', 'Goodbye', 'Hello, world!')
.
Why not?
Pip it.
$ pip install wraphper
Import the module and then fulfil your PHP fantasies in Python:
import wraphper as php
a = [1, 2, 3]
php.count(a)
# outputs: 3
This module is a work in progress. Not all functions are supported yet. The current list includes:
PRs with more functions are welcome!
wraphper doesn't internally call PHP to run these functions, it simply provides you a PHP-like function name that runs the Python equivalent. As such, performance is unaffected because only Python is running.
Similarly, there are no implications of this on security.
Follow these rules with contributed functions:
- The function must be an native PHP function, not from a third-party library.
- The name of the function must match the original exactly. Otherwise, the purpose of this module is defeated.
- The function should take the exact same number of arguments as the original.
- The argument types must match the PHP types as closely as possible, so
string
isstr
,int
isint
,array
islist
ordict
, etc. - The function must throw an appropriate exception with the exact same error message from the PHP function.
- The function should avoid any pre- or post-processing of the argument or return value. The goal is not to match PHP functions' inputs and outputs, but to provide a PHP-familiar syntax for Python developers.
Tests can be run by the following command:
$ python tests.py
wraphper has been checked with Python 2.7 and 3.6, but there's no reason why it shouldn't work with older versions.
- Added
str_replace
- BREAKING Removed class to make it easier to import and use
- Added tuple support
- Added more tests
- Added changelog
- Added tests
- Initial release with
count
function