Python Differences
Scriptling is inspired by Python but has intentional limitations for embedded scripting. This page documents what’s NOT supported and key differences.
Python Features NOT Supported
Language Features
| Feature | Notes |
|---|---|
async/await |
Asynchronous programming is not supported |
Generators with yield |
Generator functions are not supported |
| Type annotations | Type hints like def func(x: int) -> str: are not parsed |
Walrus operator (:=) |
Assignment expressions are not supported |
Positional-only separator (/) |
Positional-only parameter syntax is not supported; bare * keyword-only parameters are supported |
| Multiple inheritance | Only single inheritance is supported |
| Nested classes | Classes cannot be defined inside other classes/functions |
| Metaclasses | Custom metaclasses are not supported |
| Descriptors | The descriptor protocol is not implemented |
Regex backreferences (\1, \2) |
RE2 engine used; no backreferences, lookaheads, or lookbehinds: see regex docs |
Built-in Functions NOT Supported
| Function | Alternative |
|---|---|
input() |
Not available in embedded environments |
open() |
Use os.read_file() and os.write_file() |
compile(), eval(), exec() |
Dynamic code execution not supported |
globals(), locals() |
Scope introspection not available |
vars() |
Variable introspection not supported |
__import__() |
Use import statement |
memoryview(), bytearray(), bytes() |
Advanced byte manipulation not supported |
complex() |
Complex numbers not implemented |
frozenset() |
Use regular set() |
Standard Library NOT Included
| Module | Notes |
|---|---|
asyncio |
Async I/O framework |
threading, multiprocessing |
Use runtime.background: shared=True for shared-env threads, default for isolated parallel workers |
socket |
Low-level networking; use requests for HTTP |
pickle, marshal |
Use json for serialization |
struct |
Binary data structures |
array |
Typed arrays |
ctypes, cffi |
Foreign function interfaces |
sqlite3 |
Database access |
xml |
Use html.parser for HTML |
email, smtplib |
Email handling |
argparse, optparse |
Command-line parsing |
unittest, doctest |
Use assert statements |
pdb |
Debugger |
profile, cProfile |
Profiling tools |
Exception Handling Differences
| Feature | Notes |
|---|---|
| Exception hierarchy | Simplified error model |
| Exception groups (Python 3.11+) | Not supported |
except* syntax |
Not supported |
raise X from Y |
Exception chaining not supported; use raise ExcType(msg) directly |
| Custom exception classes | Cannot inherit from built-in exception types |
Other Differences
| Feature | Notes |
|---|---|
Module __all__ |
Export lists are not used |
__future__ imports |
Not applicable |
__next__ returning a StopIteration() value |
Ends iteration without yielding it — only raising StopIteration signals end-of-iteration |
| Default argument evaluation | Defaults are evaluated on each call (Python evaluates once, at def time) |
| Lazy iteration | any/all/sorted/min/max/map/filter materialize their iterable eagerly; any([True, boom()]) raises where Python short-circuits |
Supported Python 3 Features
Scriptling does support:
- ✅ Classes with single inheritance and
super() - ✅ Dunder methods:
__str__,__repr__,__len__,__bool__,__eq__,__lt__,__gt__,__le__,__ge__,__ne__,__contains__,__iter__,__next__,__enter__,__exit__ - ✅ Dunders honored everywhere: container membership/lookup use
__eq__/__hash__, and comparisons reflect (b.__gt__(a)whenadefines no__lt__) - ✅ Lambda functions and closures
- ✅ List comprehensions, dict comprehensions, and set comprehensions
- ✅ Generator-expression syntax, evaluated eagerly and materialized rather than returned as a lazy generator object
- ✅ Multiple
forclauses in comprehensions ([x for x in a for y in b]) - ✅ Iterators (
range,map,filter,enumerate,zip) - ✅ Dictionary views (
keys(),values(),items()) - ✅ F-strings and
.format() - ✅ True division (
/always returns float) - ✅ Set literals
{1, 2, 3}and set operations - ✅ Set hashability:
TypeErrorraised for unhashable types (lists, dicts, sets, instances without__hash__) matching Python semantics - ✅ Bool arithmetic:
True + True == 2,True == 1,False == 0 - ✅ String comparison operators (
<,>,<=,>=) - ✅ Implicit tuple packing (
x = 1, 2,return a, b,t = 42,) - ✅ Chained assignment (
a = b = 5) - ✅ Try/except/else/finally error handling
- ✅ Multiple assignment and tuple unpacking
- ✅ Extended unpacking with
* - ✅ Variadic arguments (
*args) - ✅ Keyword-only parameters with bare
* - ✅ Keyword arguments (
**kwargs) - ✅ Default parameter values
- ✅ Conditional expressions (ternary operator)
- ✅ Augmented assignment (
+=,-=,**=, etc.) - ✅ Slice notation with step (
[start:stop:step]) - ✅
delfor variables, list indexes, list slices, dict keys, and attributes - ✅
isandis notoperators - ✅
inandnot inoperators - ✅ Bitwise operators (
&,|,^,~,<<,>>) - ✅ Boolean operators with short-circuit evaluation
- ✅ Assert statements (
assert condition, "message") - ✅ Context managers (
with/as,__enter__/__exit__) - ✅ String methods (most Python string methods)
- ✅ List, dict, set methods (most Python methods)
- ✅
@property,@staticmethod,@classmethoddecorators - ✅
for/elseandwhile/else - ✅
match/casewith OR patterns (case 1 | 2 | 3:) - ✅
__name__variable with"__main__"for main scripts and module name for imports
Key Behavioral Differences
HTTP Response Object
Python requests returns attributes, Scriptling returns an object:
# Python
response.json() # Method call
response.text # Attribute
# Scriptling
response.json() # Method call
response.text # Attribute
response.body # Legacy alias for response.text; prefer text
response.status_code # AttributeLibrary Import
Scriptling uses dynamic imports that load libraries on first use:
# Both work the same
import json
import requests
# Library is loaded when first accessed
data = json.loads('{"key": "value"}')Default Timeout
HTTP requests have a default 5-second timeout:
# Python - no default timeout (hangs forever)
response = requests.get("https://slow-api.com")
# Scriptling - 5 second default
response = requests.get("https://slow-api.com") # Times out after 5s
# Explicit timeout
response = requests.get("https://slow-api.com", {"timeout": 30})No Implicit Type Coercion
# Python - implicit conversion
"Count: " + 5 # Error in Python 3, worked in Python 2
# Scriptling - explicit conversion required
"Count: " + str(5) # "Count: 5"File System Access
File access is sandboxed by default:
# Python - full file system access
f = open("/etc/passwd", "r")
# Scriptling - requires os library with allowed paths
import os
# Only works if /etc is in allowed paths
content = os.read_file("/etc/passwd")Errors and Exceptions Are Catchable, Except SystemExit
try/except catches runtime Errors (type errors, name errors, and so on) and ordinary explicitly raised Exceptions. When an Error is caught, Scriptling infers the exception type from the error message. SystemExit is the exception: it bypasses script except handlers, runs finally blocks, and returns to the Go host.
# A runtime Error is caught, with its type inferred
try:
x = undefined_variable # produces a NameError-flavoured Error
except NameError:
print("Caught!") # This runs
# An explicitly raised Exception is caught too
try:
raise ValueError("Custom error")
except Exception:
print("Caught!") # This runsMigration Tips
From Python to Scriptling
-
Replace
open()withoslibrary (withworks for custom context managers, but there is no built-inopen()):# Python with open("file.txt") as f: content = f.read() # Scriptling import os content = os.read_file("file.txt") -
Use the response JSON helper:
# Python and Scriptling data = response.json() -
Avoid async/await:
# Python async def fetch(): response = await client.get(url) # Scriptling - synchronous only def fetch(): return requests.get(url) -
Use match/case instead of complex if/elif:
# Both work if status == 200: handle_success() elif status == 404: handle_not_found() match status: case 200: handle_success() case 404: handle_not_found()
See Also
- Syntax Rules - Scriptling syntax
- Functions - Function parameters
- Error Handling - Error vs Exception
- Classes - Class limitations