sys.argv support: Consider call PySys_SetArgv on python initialization.
Open
@davidhewitt is already working on this.
Since Oct 18, 2020.
needs-design
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
Currently if I use sys.argv in python code, it would complain: 'module' object has no attribute 'argv'
This is because python's argv is not initialized.
I hope PyO3 can provide an option to initialize argv in its initialization.
Repro Example
use pyo3::prelude::*;
fn main_(py: Python) -> PyResult<()> {
let sys = py.import("sys")?;
let argv: Vec<String> = sys.get("argv")?.extract()?;
println!("{:?}", argv);
Ok(())
}
fn main() -> Result<(), ()> {
Python::with_gil(|py| {
main_(py).map_err(|e| {
e.print_and_set_sys_last_vars(py);
})
})
}
Output:
AttributeError: module 'sys' has no attribute 'argv'
Error: ()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.