pub struct PyFile { /* private fields */ }
Expand description
Python file object
Note: Only available with std
feature - requires OS I/O capabilities
Implementations§
Source§impl PyFile
impl PyFile
Sourcepub fn read(&mut self) -> Result<String, PyException>
pub fn read(&mut self) -> Result<String, PyException>
Python file.read() method
Sourcepub fn readline(&mut self) -> Result<String, PyException>
pub fn readline(&mut self) -> Result<String, PyException>
Python file.readline() method
Sourcepub fn write<D: AsRef<str>>(&mut self, data: D) -> Result<usize, PyException>
pub fn write<D: AsRef<str>>(&mut self, data: D) -> Result<usize, PyException>
Python file.write() method
Examples found in repository?
examples/std_vs_nostd.rs (line 15)
4fn main() {
5 use stdpython::*;
6
7 println!("=== STD MODE EXAMPLE ===");
8
9 // Standard I/O operations available
10 print("Hello from std mode!");
11
12 // File operations available
13 match open("example.txt", Some("w")) {
14 Ok(mut file) => {
15 let _ = file.write("Hello, file system!");
16 let _ = file.close();
17 println!("File operations work in std mode");
18 },
19 Err(e) => println!("File error: {}", e),
20 }
21
22 // All core functions work the same
23 let nums = vec![1, 2, 3, 4, 5];
24 println!("sum([1,2,3,4,5]) = {}", sum(&nums[..]));
25 println!("abs(-42) = {}", abs(-42i64));
26 println!("str(true) = '{}'", str(true));
27
28 // Collections work
29 let mut list = PyList::from_vec(vec![10, 20, 30]);
30 list.append(40);
31 println!("PyList after append: len = {}", len(&list));
32
33 println!("=== PyO3 and python-mod integration available ===");
34}
Sourcepub fn writelines<S: AsRef<str>>(
&mut self,
lines: &[S],
) -> Result<(), PyException>
pub fn writelines<S: AsRef<str>>( &mut self, lines: &[S], ) -> Result<(), PyException>
Python file.writelines() method
Sourcepub fn close(&mut self) -> Result<(), PyException>
pub fn close(&mut self) -> Result<(), PyException>
Python file.close() method
Examples found in repository?
examples/std_vs_nostd.rs (line 16)
4fn main() {
5 use stdpython::*;
6
7 println!("=== STD MODE EXAMPLE ===");
8
9 // Standard I/O operations available
10 print("Hello from std mode!");
11
12 // File operations available
13 match open("example.txt", Some("w")) {
14 Ok(mut file) => {
15 let _ = file.write("Hello, file system!");
16 let _ = file.close();
17 println!("File operations work in std mode");
18 },
19 Err(e) => println!("File error: {}", e),
20 }
21
22 // All core functions work the same
23 let nums = vec![1, 2, 3, 4, 5];
24 println!("sum([1,2,3,4,5]) = {}", sum(&nums[..]));
25 println!("abs(-42) = {}", abs(-42i64));
26 println!("str(true) = '{}'", str(true));
27
28 // Collections work
29 let mut list = PyList::from_vec(vec![10, 20, 30]);
30 list.append(40);
31 println!("PyList after append: len = {}", len(&list));
32
33 println!("=== PyO3 and python-mod integration available ===");
34}
Auto Trait Implementations§
impl Freeze for PyFile
impl RefUnwindSafe for PyFile
impl Send for PyFile
impl Sync for PyFile
impl Unpin for PyFile
impl UnwindSafe for PyFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more