php2python icon indicating copy to clipboard operation
php2python copied to clipboard

Nice little tool

Open sfinktah opened this issue 3 years ago • 0 comments

This, a bit of regex, and a few previously created shims did the trick for a tiny bit of code.

Thought I would include those shims for other people. They are quick and nasty :)

from collections import defaultdict

def array(*args):
    return defaultdict(array)
def array_keys(a):
    if isinstance(a, list):
        return range(len(a))
    return a.keys()
def array_shift(a):
    return a.pop(0)
def foreach(a):
    if isinstance(a, list):
        return enumerate(a)
    return a.items()
def explode(by, s):
    return s.split(by)
def implode(by, a):
    if isinstance(a, list):
        return by.join(a)
    raise TypeError('Not a list')
def count(a):
    return len(a)
def strlen(a):
    return len(a)
def array_reverse(array):
    copy = array[:]
    copy.reverse()
    return copy
def ucfirst(s):
    if len(s) > 1:
        return s[0].upper() + s[1:]
    if len(s):
        return s[0].upper()
    return s

STDOUT = STDERR = 0
def fprintf(dst, fmt, *args):
    print(fmt, *args)

false = False
true = True

sfinktah avatar May 17 '21 05:05 sfinktah