Skip to main content

Python module for implement object with syntax from JavaScript

Project description

asjs

Python module for implement object with syntax from JavaScript. Implementing access to keys by obj.path.to.your.key notation as in JavaScript

downloads downloads downloads supported versions pypi pypi github top language github last commit github release date github repo stars

Installing

pip install asjs

or like this:

curl https://github.com/tankalxat34/pyasjs/raw/main/asjs.py -o asjs.py

Using

Recommended import statement:

from asjs import ObjectNotation

Creating new object

Using dictionary:

obj = ObjectNotation({"key1": "value1", "key2": "value2", "key3": {"a": "b", "lst": [14, 5, 6, 12]}})

Using arguments:

obj = ObjectNotation(key1="value1", key2="value2", key3={"a": "b", "lst": [14, 5, 6, 12]})

Getting values by keys or indexes

>>> obj[0]
value1
>>> obj.key2
value2
>>> obj["key3"]
[14, 5, 6, 12]

Creating new keys in object

obj.year = 2023

or:

>>> obj.set("year", 2023)

or:

>>> year = 2023
>>> obj.set(year)

or:

>>> obj["year"] = 2023

Saving functions in object

>>> obj.fibonachi = lambda n: 1 if n <= 2 else obj.fibonachi(n - 1) + obj.fibonachi(n - 2)

>>> obj.fibonachi(7)
13

Removing keys by string-names or indexes

>>> del obj.year

or:

>>> del obj[-1]

or:

>>> del obj["year"]

Changing value by key

>>> obj.key1 = 123

or:

>>> obj["key1"] = 123

Cycle for by object

Indexes:

>>> for i in range(len(obj)):
...     print(i)
0
1
2

Keys:

>>> for k in obj:
...     print(k)
key1
key2
key3
fibonachi

Values:

>>> for v in obj.values():
...     print(v)
123
value2
JSObject(a: 'b', lst: JSObject(0: 14, 1: 5, 2: 6, 3: 12))
<function <lambda> at 0x0000020189F19480>

Boolean statements

>>> "key3" in obj
True
>>> "fake_key" in obj
False

Project details


Download files

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

Source Distribution

asjs-0.1.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

asjs-0.1.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file asjs-0.1.2.tar.gz.

File metadata

  • Download URL: asjs-0.1.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.5 Windows/10

File hashes

Hashes for asjs-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b0d80d80820c4212f34652d240409eb817cfb6d26b19514ca91e000f242f87c7
MD5 45163138338c2c7ca504c1dd8ebd46a0
BLAKE2b-256 1f79153c5d63a84fb5d15a6b1bd962701db37fdbfbbc70881a0b6dea6a2aafa7

See more details on using hashes here.

File details

Details for the file asjs-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: asjs-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.5 Windows/10

File hashes

Hashes for asjs-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab285255f74d73fb96bc4256558703b921c507e2a3a1771f58ef7b1bf1c6fdf9
MD5 2765d8eb24551bb7e55371dba5cbe853
BLAKE2b-256 b73f49afa23f740b85bc58b650ffe8a50dda1763dc01f0cb83fc1aec68fd0cbe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page