Skip to content
This repository was archived by the owner on Mar 29, 2021. It is now read-only.

Javascript type objects in Python. The module helps us to create javascript objects in the python language :slight_smile:

License

Notifications You must be signed in to change notification settings

code-roller/python-javascript-objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Javascript objects in Python

Javascript type objects in Python

Usage

To make a new JsObject:

import jsobj

a = jsobj.JsObject({
   "first_letter": True, # `A` is the first letter of the alphabet
   "vowel": True, # `A` is a vowel
   "alphabet_position": 1, # `A` is the first letter of the alphabet
   "consonant": False, # `A` is not a consonant
   "examples_of_use": ["apple", "alkali", "algebra", "alligator", "acid"] # `A` is used in all these words
   "famous_example": "apple" # Out of all words, apple is the most well known that starts with `A`
})

To add an attribute:

a.addAttr("in_hello", False) # adds the attribute `in_hello` and sets it to boolean `False`

To change the value of an existing attribute:

a.setAttr("examples_of_use", ["apple", "alkali", "algebra", "alligator", "acid", "all"]) # changes the list of examples

To delete an attribute:

a.delAttr("consonant") # deletes the consonant attribute

To get the object:

a_object = a.getObj()

To add a method to the object (can also be used to refresh the object after the dictionary is changed):

# define your method as a normal function
def a_print():
    print("A is for apple")

# add the attribute
a.addMethod(a_print)

# refresh the object
a_object = a.getObj()

# call the method (optional)
a_object.printA()

About

Javascript type objects in Python. The module helps us to create javascript objects in the python language :slight_smile:

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages