Almenon / Almenon/AREPL-backend
overload print
- Lingua principale
- Python
- Stelle
- 14
- Fork
- 8
- Merge medio
- 4g 19h
- PR unite (30g)
- 4
Descrizione
see https://github.com/Almenon/AREPL-vscode/issues/4
```python
from collections import Iterable
import json
import inspect
import sys
class MetaPrint:
def __init__(self, line_num, file_name, values):
self.line_num = line_num
self.file_name = file_name
self.message = values
def print_overload(*values, sep=' ', end='\n', file=sys.stdout, flush=False):
# if print is writing to file we dont want to record metadata
if file != sys.stdout and file != sys.stderr:
print(values, sep, end, file, flush)
return
calling_frame = inspect.currentframe().f_back
calling_filename = calling_frame.f_code.co_filename
calling_lineno = calling_frame.f_lineno
message = str(values[0] if len(values) > 0 else "")
for val in values[1:]:
message += sep + str(val)
metaPrint = MetaPrint(calling_lineno, calling_filename, message)
print_output(metaPrint)
# tests
print_overload()
print_overload("hello world")
print_overload("hello world", 1)
print_overload("hello world", 1, sep='-')
# assign startingLocals print to print_overload
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.