Wie baue ich Modulhierarchie mit Pyo3 auf?Python

Python-Programme
Anonymous
 Wie baue ich Modulhierarchie mit Pyo3 auf?

Post by Anonymous »

Versuch, Module Hierarchie mit Pyo3 und diesem Code zu erstellen. < /p>

Code: Select all

pub mod types;
pub mod sources;

use pyo3::prelude::*;
use pyo3::wrap_pymodule;

use sources::file::{find_days, read_many, read_one};

#[pymodule]
fn file(_py: Python, m: &PyModule) -> PyResult {

#[pyfn(m, "find_days")]
fn find_days_py(_py: Python, dir: String) -> PyResult {
let out = find_days(&dir)?;
Ok(out.iter().map(|x| String::from(x.to_str().unwrap())).collect())
}

Ok(())
}

#[pymodule]
fn sources(_py: Python, m: &PyModule) -> PyResult {
m.add_wrapped(wrap_pymodule!(file))?;
Ok(())
}

#[pymodule]
fn cstuff(_py: Python, m: &PyModule) -> PyResult {
m.add_wrapped(wrap_pymodule!(sources))?;
// m.add("__path__", vec![""])?;
Ok(())
}
< /code>

Code erstellt und funktioniert gut, außer dass ich diesen Fehler erhalte, wenn ich versuche, ihn zu importierenIn [1]: import cstuff.sources.file
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
 in 
----> 1 import cstuff.sources.file

ModuleNotFoundError: No module named 'cstuff.sources'; 'cstuff' is not a package

Aus dem, was ich aus der Python -Dokumentation verstehe, ist das Modul ein Paket, wenn es __path __ Attribut hat. .SO Datei, die erwartet wird. Wie kann ich das beheben, gibt es eine Möglichkeit, Python zu zwingen, __Path __ ?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post