Skip to content

Commit 5734cc3

Browse files
Manual review of builtin functions: print-repr
1 parent 87b2009 commit 5734cc3

3 files changed

Lines changed: 0 additions & 126 deletions

File tree

docs/builtins/help.md

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -154,62 +154,8 @@ docstring = obj.__doc__
154154
help(obj) # O(m) - slower but formatted
155155
```
156156

157-
### pydoc Module
158-
159-
```python
160-
import pydoc
161-
162-
# O(n) - more control
163-
docs = pydoc.getdoc(str) # Get formatted documentation
164-
pydoc.render_doc(str) # Get as HTML
165-
166-
# Server mode - browse documentation
167-
pydoc.start_server(port=8000)
168-
```
169-
170-
### inspect Module
171-
172-
```python
173-
import inspect
174-
175-
# O(1) - fast attribute access
176-
signature = inspect.signature(my_func)
177-
source = inspect.getsource(my_func)
178-
members = inspect.getmembers(obj) # O(n)
179-
180-
# More programmatic than help()
181-
```
182-
183-
## Interactive Help System
184-
185-
```python
186-
# help() without arguments
187-
# Starts interactive help system
188-
189-
# help()
190-
# Then type:
191-
# >>> list.append (shows help for list.append)
192-
# >>> modules (shows all available modules)
193-
# >>> keywords (shows Python keywords)
194-
# >>> topics (shows special topics)
195-
# >>> quit (exits help)
196-
```
197-
198157
## Practical Examples
199158

200-
### Documentation Lookup
201-
202-
```python
203-
# O(m) - find how to use a function
204-
def understand_function(func):
205-
help(func)
206-
207-
# Examples:
208-
understand_function(len)
209-
understand_function(str.split)
210-
understand_function(dict.get)
211-
```
212-
213159
### Debugging Unknown Objects
214160

215161
```python
@@ -267,34 +213,6 @@ def get_help(obj):
267213
# Faster than calling help() repeatedly
268214
```
269215

270-
## Advanced Usage
271-
272-
### Programmatic Documentation Access
273-
274-
```python
275-
# O(m) - get docs without printing
276-
import pydoc
277-
278-
docs = pydoc.render_doc(str, title="String Documentation")
279-
# Returns formatted HTML string
280-
281-
# Use in web server, etc.
282-
```
283-
284-
### Documentation Server
285-
286-
```python
287-
import pydoc
288-
289-
# Start local documentation server
290-
# pydoc.start_server(port=8000)
291-
# Then visit http://localhost:8000
292-
293-
# Or generate HTML
294-
pydoc.writedoc(str, outdir="/tmp/docs")
295-
# Creates HTML documentation file
296-
```
297-
298216
## Edge Cases
299217

300218
### Objects Without Docstrings
@@ -334,15 +252,12 @@ help(func) # Shows custom docstring
334252
- Use `help()` for interactive exploration
335253
- Use `help(topic)` to learn about Python features
336254
- Check `__doc__` attribute directly in code
337-
- Use `inspect` module for programmatic access
338-
- Write clear docstrings for your functions
339255

340256
**Avoid**:
341257

342258
- Using `help()` in tight loops (call once, cache result)
343259
- Assuming `help()` output format is stable
344260
- Using `help()` for production code (direct access faster)
345-
- Forgetting to write docstrings
346261

347262
## Related Functions
348263

docs/builtins/print.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,6 @@ print("Value: %s" % value) # O(n) - conversion cost
115115

116116
## I/O Considerations
117117

118-
### Output Buffering
119-
120-
```python
121-
# I/O overhead dominates over string computation
122-
import sys
123-
124-
# Unbuffered output
125-
for i in range(1000):
126-
print(i, flush=True) # Forces write immediately
127-
# Slower due to I/O flushing
128-
129-
# Buffered output (default)
130-
for i in range(1000):
131-
print(i) # Buffered, faster overall
132-
```
133-
134118
### Writing to Files
135119

136120
```python
@@ -219,10 +203,7 @@ print(lst) # Output: [[...]] - handles circular refs
219203

220204
**Do**:
221205

222-
- Use `print()` for simple output (it's designed for this)
223206
- Collect strings then print once for massive output
224-
- Use `end=""` or `sep=""` to control formatting
225-
- Print to file with `file=` parameter
226207

227208
**Avoid**:
228209

docs/builtins/repr.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,6 @@ items = [Item(i) for i in range(10)]
120120
repr(items) # O(10) - calls __repr__ on each item
121121
```
122122

123-
## Difference from str()
124-
125-
```python
126-
# str() - human-readable, may be different
127-
class Value:
128-
def __str__(self):
129-
return "A nice value"
130-
131-
def __repr__(self):
132-
return "Value()"
133-
134-
v = Value()
135-
print(str(v)) # "A nice value"
136-
print(repr(v)) # "Value()"
137-
138-
# repr() should return valid Python code if possible
139-
x = 42
140-
assert eval(repr(x)) == x # True for most cases
141-
142-
s = "hello"
143-
assert eval(repr(s)) == s # True - repr() is evaluable
144-
```
145123

146124
## String Escaping
147125

0 commit comments

Comments
 (0)