Update os.md

This commit is contained in:
blueloveTH 2024-01-31 21:42:57 +08:00
parent cd2de2c388
commit 5e55df9b97

View File

@ -42,3 +42,19 @@ Check if the given path exists.
### `os.path.basename(path: str)` ### `os.path.basename(path: str)`
Returns the basename of the given path. Returns the basename of the given path.
## Other functions
You can add other functions to `os` module via normal binding if you need them.
For example, add `os.system`:
```cpp
PyObject* mod = vm->_modules["os"];
vm->bind(mod, "system(cmd: str) -> int", [](VM* vm, ArgsView args){
const char* cmd = py_cast<CString>(vm, args[0]);
int code = system(cmd);
return py_var(vm, code);
});
```