reprexlite¶
Attributes¶
Classes¶
Functions¶
reprex(input, outfile=None, venue='gh', advertise=None, session_info=False, style=False, comment='#>', old_results=False, print_=True, terminal=False)
¶
Render reproducible examples of Python code for sharing. This function will evaluate your
code and returns an instance of a Reprex subclass. Calling
str(...) on the Reprex object will return your code with the evaluated results embedded
as comments, plus additional markup appropriate to the sharing venue set by the venue keyword
argument.
For example, for the gh venue for GitHub Flavored Markdown, you'll get a reprex whose string
representation looks like:
```python
x = 2
x + 2
#> 4
```
<sup>Created at 2021-02-15 16:58:47 PST by [reprexlite](https://github.com/jayqi/reprexlite) v0.1.0</sup>
The supported venue formats are:
gh: GitHub Flavored Markdownso: StackOverflow, alias for ghds: Discourse, alias for ghhtml: HTMLpy: Python scriptrtf: Rich Text Formatslack: Slack
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str
|
Block of Python code |
required |
outfile
|
Optional[Path]
|
Optional file path to write reprex to. Defaults to None. |
None
|
venue
|
str
|
Determines the output format by the venue you want to share the code. Defaults to "gh" for GitHub Flavored Markdown. |
'gh'
|
advertise
|
Optional[bool]
|
Whether to include a note that links back to the reprexlite
package. Default |
None
|
session_info
|
bool
|
Whether to include additional details about your Python version, operating system, and installed packages. Defaults to False. |
False
|
style
|
bool
|
Whether to autoformat your code with black. Defaults to False. |
False
|
comment
|
str
|
Line prefix to use for displaying evaluated results. Defaults to "#>". |
'#>'
|
old_results
|
bool
|
Whether to keep old results, i.e., comment lines in input that match
the |
False
|
print_
|
bool
|
Whether to print your reprex to console. Defaults to True. |
True
|
terminal
|
bool
|
Whether to use syntax highlighting for 256-color terminal display. Requires optional dependency Pygments. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Reprex
|
Instance of a |
Source code in reprexlite/reprex.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |