MCPcopy Index your code
hub / github.com/RustPython/RustPython / print

Function print

crates/vm/src/stdlib/builtins.rs:992–1020  ·  view source on GitHub ↗
(objects: PosArgs, options: PrintOptions, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

990
991 #[pyfunction]
992 pub fn print(objects: PosArgs, options: PrintOptions, vm: &VirtualMachine) -> PyResult<()> {
993 let file = match options.file {
994 Some(f) => f,
995 None => sys::get_stdout(vm)?,
996 };
997 let write = |obj: PyStrRef| vm.call_method(&file, "write", (obj,));
998
999 let sep = options.sep.unwrap_or_else(|| vm.ctx.new_str(" "));
1000
1001 let mut first = true;
1002 for object in objects {
1003 if first {
1004 first = false;
1005 } else {
1006 write(sep.clone())?;
1007 }
1008
1009 write(object.str(vm)?)?;
1010 }
1011
1012 let end = options.end.unwrap_or_else(|| vm.ctx.new_str("\n"));
1013 write(end)?;
1014
1015 if options.flush.into() {
1016 vm.call_method(&file, "flush", ())?;
1017 }
1018
1019 Ok(())
1020 }
1021
1022 #[pyfunction]
1023 fn repr(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyStrRef> {

Callers 15

displayhookFunction · 0.70
_print_panicMethod · 0.50
wdriverFunction · 0.50
mainFunction · 0.50
asyncbrowser.pyFile · 0.50
mandelFunction · 0.50
mainFunction · 0.50
fetch_handlerFunction · 0.50
fetch.pyFile · 0.50
fizzbuzz.pyFile · 0.50
fibonacci.pyFile · 0.50
imaplib.pyFile · 0.50

Calls 6

get_stdoutFunction · 0.85
writeFunction · 0.70
call_methodMethod · 0.45
new_strMethod · 0.45
cloneMethod · 0.45
strMethod · 0.45

Tested by 15

_print_panicMethod · 0.40
wdriverFunction · 0.40
_findMethod · 0.40
summarizeMethod · 0.40
debug_scriptFunction · 0.40
callbackMethod · 0.40
check_annotationsMethod · 0.40
tearDownModuleFunction · 0.40
verbose_printFunction · 0.40