See Syntax/type support for an overview of what types and operations are supported. Jia Mini Python does not have an internal object model - instead Java types are used directly. This keeps the code considerably smaller. But it also means that most Python attributes (eg functions) do not exist. For example in Python integers have 64 different attributes while they have none in this implementation.
Returns a new dictionary with the same contents, but changes to the new one do not affect the original.
Returns value associated with key, and if it doesn’t exist then default.
Copies all items from other into this dict.
Adds item to end of this list
Appends every member of list to this list
Returns position of item in list or -1 if not found.
Reverses the order of the elements in the list
Removes the last item in the list and returns it
You can omit some or all of the arguments. Since keyword arguments are not supported you will need to supply preceding arguments.
Parameters: |
|
---|
Unlike Python’s implementation this does require that cmp and key are callables if supplied.
Returns True if the string ends with the specified suffix.
Return a string which is the concatenation of the strings in the list, separated by this string.
Returns lower case version of string by calling String.toLowerCase (Java) NSString lowercaseString (ObjC).
Returns a new string replacing all occurrences of target with replacement.
Parameters: | |
---|---|
Returns: | List of substrings (each not including the separator) |
Splits string into a list of substrings around sep stopping when maxsplits have been found.
Returns True is the string starts with prefix.
Returns new string omitting leading and trailing whitespace.
Returns upper case version of string by calling String.toUpperCase (Java) NSString uppercaseString (ObjC).
Parameters: |
|
---|
Since *args is not supported, this is how to call something when you have built up the arguments in a list.
Returns a boolean for the item. For example it is True for non-zero integers and strings/list/dict that contain at least one item.
Returns a boolean indicating if the item can be called as a function.
Compares left against right depending on if they are less, equal or greater. (Note)
Returns a new list consisting of members when function(member) returned true.
Returns a dict of global variables. You can modify the contents.
Returns a numeric code uniquely representing this instance. Behind the scenes it returns the result of System.getIdentityHashcode() (Java) or the object pointer (ObjC).
Returns integer of item. int items are returned as is, bools as 0/1 for False/True and strings are parsed. Note that this implementation does not take a base/radix argument.
Returns length of item such as number of characters for a str, members in a list/dict.
Returns a dict of local variables. You can modify the contents.
Returns a new list consisting of function applied to each list member. Use this an alternate to list comprehensions.
Prints the items after converting them to strings and separating with a space. A newline is always emitted. You will only be able to call this function if you ran jmp-compile under Python 3 or supplied the –print-function argument.
Returns a list of integers between start (inclusive) and stop (exclusive) each incrementing by step. Step can be negative.
Returns the string corresponding to item.
For non basic types their toString() (Java) NSObject description (ObjC) method is called.
Unlike regular Python this returns a string. For the basic types it will be the expected name. For others it will be their Class.getSimpleName() (Java) or class description (ObjC)
You can do a form of object oriented programming where you keep data and the methods that operate on it together in the same dictionary. This is because of two features on dictionaries - attribute access and implicit self if attribute access returns a method.
Jia Mini Python lets you access dictionaries the regular Python way and as attribute access:
d={"a": 3}
# normal way
d["a"]
# attribute access
d.a
If you add a method to a dictionary and then access the method via attribute access then the dictionary will be added as an implicit first parameter in calls, which you traditionally call self.:
def meth(self, a):
pass
d={"meth": meth}
# This call
d.meth(3)
# becomes this behind the scenes
meth(d, 3)
# Dictionary access won't and this will complain about not enough
# parameters
d["meth"](3)
Here is an example of being somewhat object oriented by using dictionaries with methods. (Technically this is substantially similar to prototype based programming and similar to how Javascript works.):
# How we make new ones
def Circle(x, y, radius):
def area(self):
return radius*radius*31415/10000
def draw(self, graphics):
graphics.plot(...)
return {
# data members
"x": x,
"y": y,
"radius": radius,
# method members
"area": area,
"draw": draw}
# If you are happy exposing everything then this works
return locals()
# This is how we make a new instance
circ=Circle(25, 3, 12)
print circ.area()