std

package
v0.8.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const LLGoPackage = "py.builtins"

Variables

This section is empty.

Functions

func Abs

func Abs(x *py.Object) *py.Object

func Aiter

func Aiter(asyncIterable *py.Object) *py.Object

Return an AsyncIterator for an AsyncIterable object.

func All

func All(iterable *py.Object) *py.Object

Return True if bool(x) is True for all values x in the iterable.

If the iterable is empty, return True.

func Anext

func Anext(asyncIterator *py.Object) *py.Object

awaitable anext(async_iterator)

func AnextEx

func AnextEx(asyncIterator, default_ *py.Object) *py.Object

awaitable anext(async_iterator, default)

When awaited, return the next item from the given asynchronous iterator, or default if given and the iterator is exhausted.

This is the async variant of the next() builtin, and behaves similarly.

This calls the __anext__() method of async_iterator, returning an awaitable. Awaiting this returns the next value of the iterator. If default is given, it is returned if the iterator is exhausted, otherwise StopAsyncIteration is raised.

func Any

func Any(iterable *py.Object) *py.Object

Return True if bool(x) is True for any x in the iterable.

If the iterable is empty, return False.

func Ascii

func Ascii(obj *py.Object) *py.Object

Return an ASCII-only representation of an object.

As repr(), return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by repr() using \\x, \\u or \\U escapes. This generates a string similar to that returned by repr() in Python 2.

func Bin

func Bin(number *py.Object) *py.Object

Return the binary representation of an integer.

>>> bin(2796202)
'0b1010101010101010101010'

func Breakpoint

func Breakpoint(__llgo_va_list ...any)

breakpoint(*args, **kws)

See https://docs.python.org/3/library/functions.html#breakpoint

func Callable

func Callable(obj *py.Object) *py.Object

Return whether the object is callable (i.e., some kind of function).

Note that classes are callable, as are instances of classes with a __call__() method.

func Chr

func Chr(i *py.Object) *py.Object

Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.

func Compile

func Compile(source *py.Object, filename *py.Object, mode *py.Object, flags *py.Object, dontInherit *py.Object, optimize *py.Object) *py.Object

Compile source into a code object that can be executed by exec() or eval().

The source code may represent a Python module, statement or expression. The filename will be used for run-time error messages. The mode must be 'exec' to compile a module, 'single' to compile a single (interactive) statement, or 'eval' to compile an expression. The flags argument, if present, controls which future statements influence the compilation of the code. The dont_inherit argument, if true, stops the compilation inheriting the effects of any future statements in effect in the code calling compile; if absent or false these statements do influence the compilation, in addition to any features explicitly specified.

func Delattr

func Delattr(obj *py.Object, name *py.Object) *py.Object

Deletes the named attribute from the given object.

delattr(x, 'y') is equivalent to “del x.y“

func Dir

func Dir() *py.Object

dir()

func DirEx

func DirEx(object *py.Object) *py.Object

dir(object)

func Divmod

func Divmod(x *py.Object, y *py.Object) *py.Object

Return the tuple (x//y, x%y). Invariant: div*y + mod == x.

func Eval

func Eval(source *py.Object, globals *py.Object, locals *py.Object) *py.Object

Evaluate the given source in the context of globals and locals.

The source may be a string representing a Python expression or a code object as returned by compile(). The globals must be a dictionary and locals can be any mapping, defaulting to the current globals and locals. If only globals is given, locals defaults to it.

func Exec

func Exec(source *py.Object, globals *py.Object, locals *py.Object) *py.Object

Execute the given source in the context of globals and locals.

The source may be a string representing one or more Python statements or a code object as returned by compile(). The globals must be a dictionary and locals can be any mapping, defaulting to the current globals and locals. If only globals is given, locals defaults to it. The closure must be a tuple of cellvars, and can only be used when source is a code object requiring exactly that many cellvars.

func Format

func Format(value *py.Object, formatSpec *py.Object) *py.Object

Return type(value).__format__(value, format_spec)

Many built-in types implement format_spec according to the Format Specification Mini-language. See help('FORMATTING').

If type(value) does not supply a method named __format__ and format_spec is empty, then str(value) is returned. See also help('SPECIALMETHODS').

func GetAttr

func GetAttr(object, name *py.Object) *py.Object

getattr(object, name)

func GetAttrEx

func GetAttrEx(object, name, default_ *py.Object) *py.Object

getattr(object, name, default)

func Globals

func Globals() *py.Object

Return the dictionary containing the current scope's global variables.

NOTE: Updates to this dictionary *will* affect name lookups in the current global scope and vice-versa.

func Hasattr

func Hasattr(obj *py.Object, name *py.Object) *py.Object

Return whether the object has an attribute with the given name.

This is done by calling getattr(obj, name) and catching AttributeError.

func Hash

func Hash(obj *py.Object) *py.Object

Return the hash value for the given object.

Two objects that compare equal must also have the same hash value, but the reverse is not necessarily true.

func Help

func Help(object *py.Object)

Invoke the built-in help system. (This function is intended for interactive use.) If no argument is given, the interactive help system starts on the interpreter console. If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. If the argument is any other kind of object, a help page on the object is generated.

Note that if a slash(/) appears in the parameter list of a function when invoking help(), it means that the parameters prior to the slash are positional-only. For more info, see the FAQ entry on positional-only parameters.

func Hex

func Hex(number *py.Object) *py.Object

Return the hexadecimal representation of an integer.

>>> hex(12648430)
'0xc0ffee'

func Id

func Id(obj *py.Object) *py.Object

Return the identity of an object.

This is guaranteed to be unique among simultaneously existing objects. (CPython uses the object's memory address.)

func Input

func Input(prompt *py.Object) *py.Object

Read a string from standard input. The trailing newline is stripped.

The prompt string, if given, is printed to standard output without a trailing newline before reading input.

If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available.

func Isinstance

func Isinstance(obj *py.Object, classOrTuple *py.Object) *py.Object

Return whether an object is an instance of a class or of a subclass thereof.

A tuple, as in “isinstance(x, (A, B, ...))“, may be given as the target to check against. This is equivalent to “isinstance(x, A) or isinstance(x, B) or ...“ etc.

func Issubclass

func Issubclass(cls *py.Object, classOrTuple *py.Object) *py.Object

Return whether 'cls' is derived from another class or is the same class.

A tuple, as in “issubclass(x, (A, B, ...))“, may be given as the target to check against. This is equivalent to “issubclass(x, A) or issubclass(x, B) or ...“.

func Iter

func Iter(object *py.Object) *py.Object

iter(object)

func IterEx

func IterEx(callable, sentinel *py.Object) *py.Object

iter(object, sentinel)

func Len

func Len(obj *py.Object) *py.Object

Return the number of items in a container.

func Locals

func Locals() *py.Object

Return a dictionary containing the current scope's local variables.

NOTE: Whether or not updates to this dictionary will affect name lookups in the local scope and vice-versa is *implementation dependent* and not covered by any backwards compatibility guarantees.

func Max

func Max(__llgo_va_list ...any) *py.Object

max(iterable, *, key=None) max(iterable, *, default, key=None) max(arg1, arg2, *args, key=None)

If one positional argument is provided, it should be an iterable. The largest item in the iterable is returned. If two or more positional arguments are provided, the largest of the positional arguments is returned.

func Min

func Min(__llgo_va_list ...any) *py.Object

min(iterable, *, key=None) min(iterable, *, default, key=None) min(arg1, arg2, *args, key=None)

func Next

func Next(iterator *py.Object) *py.Object

next(iterator)

func NextEx

func NextEx(iterator, default_ *py.Object) *py.Object

next(iterator, default)

Retrieve the next item from the iterator by calling its __next__() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised.

func Oct

func Oct(number *py.Object) *py.Object

Return the octal representation of an integer.

>>> oct(342391)
'0o1234567'

func Open

func Open(file *py.Object, mode *py.Object, buffering *py.Object, encoding *py.Object, errors *py.Object, newline *py.Object, closefd *py.Object, opener *py.Object) *py.Object

Open file and return a stream. Raise OSError upon failure.

file is either a text or byte string giving the name (and the path if the file isn't in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.)

mode is an optional string that specifies the mode in which the file is opened. It defaults to 'r' which means open for reading in text mode. Other common values are 'w' for writing (truncating the file if it already exists), 'x' for creating and writing to a new file, and 'a' for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent: locale.getencoding() is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are:

========= =============================================================== Character Meaning --------- --------------------------------------------------------------- 'r' open for reading (default) 'w' open for writing, truncating the file first 'x' create a new file and open it for writing 'a' open for writing, appending to the end of the file if it exists 'b' binary mode 't' text mode (default) '+' open a disk file for updating (reading and writing) ========= ===============================================================

The default mode is 'rt' (open for reading text). For binary random access, the mode 'w+b' opens and truncates the file to 0 bytes, while 'r+b' opens the file without truncation. The 'x' mode implies 'w' and raises an `FileExistsError` if the file already exists.

Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn't. Files opened in binary mode (appending 'b' to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when 't' is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

  • Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device's "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`. On many systems, the buffer will typically be 4096 or 8192 bytes long.

  • "Interactive" text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.

encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.

errors is an optional string that specifies how encoding errors are to be handled---this argument should not be used in binary mode. Pass 'strict' to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass 'ignore' to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register or run 'help(codecs.Codec)' for a list of the permitted encoding error strings.

newline controls how universal newlines works (it only applies to text mode). It can be None, ”, '\n', '\r', and '\r\n'. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in '\n', '\r', or '\r\n', and these are translated into '\n' before being returned to the caller. If it is ”, universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any '\n' characters written are translated to the system default line separator, os.linesep. If newline is ” or '\n', no translation takes place. If newline is any of the other legal values, any '\n' characters written are translated to the given string.

If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case.

A custom opener can be used by passing a callable as *opener*. The underlying file descriptor for the file object is then obtained by calling *opener* with (*file*, *flags*). *opener* must return an open file descriptor (passing os.open as *opener* results in functionality similar to passing None).

open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode ('w', 'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom.

It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode.

func Ord

func Ord(c *py.Object) *py.Object

Return the Unicode code point for a one-character string.

func Pow

func Pow(base *py.Object, exp *py.Object, mod *py.Object) *py.Object

Equivalent to base**exp with 2 arguments or base**exp % mod with 3 arguments

Some types, such as ints, are able to use a more efficient algorithm when invoked using the three argument form.

func Print

func Print(__llgo_va_list ...interface{}) *py.Object

Prints the values to a stream, or to sys.stdout by default.

sep
  string inserted between values, default a space.
end
  string appended after the last value, default a newline.
file
  a file-like object (stream); defaults to the current sys.stdout.
flush
  whether to forcibly flush the stream.

func Repr

func Repr(obj *py.Object) *py.Object

Return the canonical string representation of the object.

For many object types, including most builtins, eval(repr(obj)) == obj.

func Round

func Round(number *py.Object, ndigits *py.Object) *py.Object

Round a number to a given precision in decimal digits.

The return value is an integer if ndigits is omitted or None. Otherwise the return value has the same type as the number. ndigits may be negative.

func Setattr

func Setattr(obj *py.Object, name *py.Object, value *py.Object) *py.Object

Sets the named attribute on the given object to the specified value.

setattr(x, 'y', v) is equivalent to “x.y = v“

func Sorted

func Sorted(iterable *py.Object) *py.Object

Return a new list containing all items from the iterable in ascending order.

A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result in descending order.

func Sum

func Sum(iterable *py.Object, start *py.Object) *py.Object

Return the sum of a 'start' value (default: 0) plus an iterable of numbers

When the iterable is empty, return the start value. This function is intended specifically for use with numeric values and may reject non-numeric types.

func Vars

func Vars() *py.Object

vars()

func VarsEx

func VarsEx(object *py.Object) *py.Object

vars(object)

Return the __dict__ attribute for a module, class, instance, or any other object with a __dict__ attribute.

See https://docs.python.org/3/library/functions.html#vars

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL