Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

python dark magic

Project description


because magic is fun


pip install ambiguous


decorator: because decorators should accept args too

def suffix(fn, str_='xyz'):
    '''add a suffix to the result of the wrapped fn'''
    def wrapper(*args, **kwargs):
        return '%s_%s' % (fn(*args, **kwargs), str_)
    return wrapper

def abc(): return 'abc'

> 'abc_xyz'

def count(repeat=1): return '0' * repeat

> '0_123'
> '000_123'

thing_or_things: merges gets and multigets

def itself(args):
  return { x : x for x in args }

> 1
itself([1, 2])
> { 1 : 1, 2 : 2 }

# specified argument
def prefix(prefix, args):
  return { x : "%s_%s" % (prefix, x) for x in args }

prefix('abc', [1, 2])
> { 1 : 'abc_1', 2 : 'abc_2' }

# works with default args
def multiply(args, factor=1):
  return { x : x * factor for x in args }

> 2
multiply(2, factor=2)
> 4
multiply([1, 2], factor=3)
> { 1 : 3, 2 : 6 }

what, parentheses optional?! (warning: still highly experimental)

import ambiguous

def foo():
  return 'foo'

print foo
> 'foo'
print foo()
> 'foo'
foo + 'abc'
> 'fooabc'

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ambiguous, version 0.4.1
Filename, size File type Python version Upload date Hashes
Filename, size ambiguous-0.4.1-py3-none-any.whl (7.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size ambiguous-0.4.1.tar.gz (7.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page