Python-Cooker
ๅpythonๅฆ็นๅฐ้ฒ
ๅ ณไบpythontutorๅตๅ ฅ
่่ๅฐๆดๆนไพฟๆฅ็python็ๆง่ก่ฟ็จ๏ผ่ฟ้่่ๅฐpythontutorๆฅๅ ฅ
pythontutor้กน็ฎ่งฃๅ
่ฏดๆ
ๆฌๆไธป่ฆๅๆไธไธpythontutor็้กน็ฎ็ปๆไธไธๅกๆต็จ๏ผๅนถ็กฎๅฎๅ้ข็็ธๅ ณไปฃ็ ๅฏ่งๅ็ไฝฟ็จๆนๆณ
ๆปไฝ็ปๆๅพ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ _ _ โ
โ _ __ __ _ __| |____ _ __ _ ___ (_)___ ___ _ _ โ
โ | '_ \/ _` / _| / / _` / _` / -_)_ | (_-</ _ \ ' \ โ
โ | .__/\__,_\__|_\_\__,_\__, \___(_)/ /__/\___/_||_| โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ |_| |___/ |__/ โ
โ ___ _ _ _____ _ ___ โ โ โ
โ | _ \_ _| |_| |_ ___ _ _ |_ _| _| |_ ___ _ _ | __|_ _____ __ โ โ { โ
โ | _/ || | _| ' \/ _ \ ' \ | || || | _/ _ \ '_| | _|\ \ / -_) _| โ โ "name": "v5-unity", โ
โ |_| \_, |\__|_||_\___/_||_| |_| \_,_|\__\___/_| |___/_\_\___\__| โ โ "version": "1.0.0", โ
โ |__/ โ โ "description": "OPT v5", โ
โ โ โ "main": "bundle.js", โ
โ โ โ "repository": "https://github.com/pgbovine/OnlinePythonTutor", โ
โ โ โ "license": "BSD-3-Clause", โ
โ โ โ "scripts": { โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ "start": "python bottle_server.py", โ
โ โ โ โ โ "py3start": "python3 bottle_server.py", โ
โ โ botter_server.py โ โ โโโโโโโโโโโซ "webpack": "webpack --devtool sourcemap --progress --colors --watch", โ
โ โ get_py_exec โโโโโโโโโโโโโโ โ โ โ "production-build": "rm -f build/* && webpack && python โ
โ โ โ โ โ โ โ add_cache_busting_query_strings.py" โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ }, โ
โ โ โ โ โ "dependencies": { โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ "css-loader": "", โ
โ โโโโโโโโโโโโโถ โ โ npm run production-build โ "fs-extra": "^6.0.1", โ
โ โ pg_logger.py โ โ โ โ "json-stable-stringify": "^1.0.1", โ
โ โ exec_script_str_local โ โ โ โ "on-build-webpack": "^0.1.0", โ
โ โโโโโโโโโโโโโค โ โ โ โ "pixelmatch": "^4.0.2", โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ "puppeteer": "^1.5.0", โ
โ โ โ โ โ โ โ "script-loader": "", โ
โ โ โ โ /visualize.html โ โ โ "style-loader": "", โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโถ visualize.bundle.js โโโโโโโโโโ โ "ts-loader": "^3.5.0", โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ โ "url-loader": "" โ
โ โ โโโโโโโโโโโโโ return trace info โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ } โ
โ โ pg_logger.py โ {code: '', trace: []} โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฒโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ PGLogger._runscript โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ webpack
โ โ โ
โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโปโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ _ _ __ _ _ โ
โ โ โ __ __ _____| |__ _ __ __ _ __| |__ __ ___ _ _ / _(_)__ _ (_)___ โ
โ โ โ \ V V / -_) '_ \ '_ \/ _` / _| / /_/ _/ _ \ ' \| _| / _` |_ | (_-< โ
โ โ โ \_/\_/\___|_.__/ .__/\__,_\__|_\_(_)__\___/_||_|_| |_\__, (_)/ /__/ โ
โ โ โ |_| |___/ |__/ โ
โ โ โ entry: { โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ 'visualize': "./js/visualize.ts", โ
โ 'recorder': "./js/recorder.ts", โ
โ 'render-trace': "./js/render-trace.ts", โ
โ 'opt-live': "./js/opt-live.ts", โ
โ 'iframe-embed': "./js/iframe-embed.ts", โ
โ 'index': "./js/index.ts", โ
โ 'composingprograms': "./js/composingprograms.ts", โ
โ 'csc108h': "./js/csc108h.ts", โ
โ 'pytutor-embed': "./js/pytutor-embed.ts", โ
โ }, โ
โ โ
โ output: { โ
โ path: __dirname + "/build/", โ
โ // TODO: use 'bundle.[hash].js' for fingerprint hashing โ
โ // to create unique filenames for releases: โ
โ // https://webpack.github.io/docs/long-term-caching.html โ
โ filename: "[name].bundle.js", โ
โ sourceMapFilename: "[file].map", โ
โ }, โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
iframeไฝฟ็จ็คบไพ
ไฝฟ็จbottleๅwebๆๅก
from bottle import route, get, request, run, template, static_file
try:
import StringIO # NB: don't use cStringIO since it doesn't support unicode!!!
except:
import io as StringIO # py3
import json
import pg_logger
@route('/web_exec_<name:re:.+>.py')
@route('/LIVE_exec_<name:re:.+>.py')
@route('/viz_interaction.py')
@route('/syntax_err_survey.py')
@route('/runtime_err_survey.py')
@route('/eureka_survey.py')
@route('/error_log.py')
def dummy_ok(name=None):
return 'OK'
@route('/<filepath:path>')
def index(filepath):
return static_file(filepath, root='.')
# Note that this will run either Python 2 or 3, depending on which
# version of Python you used to start the server, REGARDLESS of which
# route was taken:
@route('/web_exec_py2.py')
@route('/web_exec_py3.py')
@route('/LIVE_exec_py2.py')
@route('/LIVE_exec_py3.py')
def get_py_exec():
out_s = StringIO.StringIO()
def json_finalizer(input_code, output_trace):
ret = dict(code=input_code, trace=output_trace)
json_output = json.dumps(ret, indent=None)
out_s.write(json_output)
options = json.loads(request.query.options_json)
pg_logger.exec_script_str_local(request.query.user_script,
request.query.raw_input_json,
options['cumulative_mode'],
options['heap_primitives'],
json_finalizer)
return out_s.getvalue()
if __name__ == "__main__":
run(host='localhost', port=8003, reloader=True)
่ฟ้ๅฏไปฅๅ็ฐ๏ผไฝ่ ็่ทฏ็ฑๅบๆฌๆฑ่ๅจget_py_exec, ่ฟๅ ฅๅๆง่กexec_script_str_local
pg_logger.pyไป็ป
โโโโโโโโโโโโโโโโโโโโโ
โ โ
โ botter_server.py โ
โ get_py_exec โโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโ โ
โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโถ โ
โ pg_logger.py โ
โ exec_script_str_local โ
โโโโโโโโโโโโโค โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโ
โ pg_logger.py โ
โ PGLogger._runscript โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
็ปงๆฟ่ชBdb
class PGLogger(bdb.Bdb):
ๅๅงๅ็ธๅ ณ
def __init__(
self,
cumulative_mode,
heap_primitives,
show_only_outputs,
finalizer_func,
disable_security_checks=False,
allow_all_modules=False,
crazy_mode=False,
custom_modules=None,
separate_stdout_by_module=False,
probe_exprs=None):
่ฐ็จๅฝๆฐ
def exec_script_str_local(
script_str,
raw_input_lst_json,
cumulative_mode,
heap_primitives,
finalizer_func,
probe_exprs=None,
allow_all_modules=False):
# ๆ ธๅฟ่ฟ่ก่ฟ็จ่ฎฐๅฝ็ฑป
logger = PGLogger(
cumulative_mode,
heap_primitives,
False,
finalizer_func,
disable_security_checks=True,
allow_all_modules=allow_all_modules,
probe_exprs=probe_exprs
)
# TODO: refactor these NOT to be globals
global input_string_queue
input_string_queue = []
if raw_input_lst_json:
# TODO: if we want to support unicode, remove str() cast
input_string_queue = [str(e) for e in json.loads(raw_input_lst_json)]
try:
logger._runscript(script_str)
except bdb.BdbQuit:
pass
finally:
return logger.finalize()
่ฟๅๆฐๆฎ็คบไพ
{
"code": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())",
"trace": [
{
"line": 5,
"event": "step_line",
"func_name": "<module>",
"globals": {},
"ordered_globals": [],
"stack_to_render": [],
"heap": {},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 19,
"event": "step_line",
"func_name": "<module>",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [],
"heap": {},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 10,
"event": "call",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601"
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 11,
"event": "step_line",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601"
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 12,
"event": "step_line",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"name",
"Pat"
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 13,
"event": "step_line",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"name",
"Pat"
],
[
"role",
"Professor"
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 14,
"event": "step_line",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 14,
"event": "return",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000,
"__return__": null
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary",
"__return__"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 20,
"event": "step_line",
"func_name": "<module>",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
],
"pat": [
"REF",
1
]
},
"ordered_globals": [
"Staff601",
"pat"
],
"stack_to_render": [],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 16,
"event": "call",
"func_name": "salutation",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
],
"pat": [
"REF",
1
]
},
"ordered_globals": [
"Staff601",
"pat"
],
"stack_to_render": [
{
"func_name": "salutation",
"is_parent": false,
"frame_id": 2,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
]
},
"ordered_varnames": [
"self"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "salutation_f2"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 17,
"event": "step_line",
"func_name": "salutation",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
],
"pat": [
"REF",
1
]
},
"ordered_globals": [
"Staff601",
"pat"
],
"stack_to_render": [
{
"func_name": "salutation",
"is_parent": false,
"frame_id": 2,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
]
},
"ordered_varnames": [
"self"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "salutation_f2"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 17,
"event": "return",
"func_name": "salutation",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
],
"pat": [
"REF",
1
]
},
"ordered_globals": [
"Staff601",
"pat"
],
"stack_to_render": [
{
"func_name": "salutation",
"is_parent": false,
"frame_id": 2,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"__return__": "Professor Pat"
},
"ordered_varnames": [
"self",
"__return__"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "salutation_f2"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 20,
"event": "return",
"func_name": "<module>",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
],
"pat": [
"REF",
1
]
},
"ordered_globals": [
"Staff601",
"pat"
],
"stack_to_render": [],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\nProfessor Pat\n"
}
]
}
ๅ่่ตๆ
- KuanHsiaoKuo/OnlinePythonTutor
- KuanHsiaoKuo/PythonTutorService: ๅบไบOnlinePythonTutorๅผๆบ้กน็ฎ่ฟ่กๆนๅ
- bdbไธpdbไป็ป
- Online Python Tutor- Embeddable Web-Based Program Visualization for CS Education.pdf
- Online python tutor: embeddable web-based program visualization for cs education
- Python Tutor code visualizer: Visualize code in Python, JavaScript, C, C++, and Java
- pathrise-python-tutor/embedding-HOWTO.md at master ยท pathrise-eng/pathrise-python-tutor
ๅบๅฑๆฝ่ฑก
่ๆๅ ๅญ็ฎก็
็ฑปๅ็ณป็ป
ๅบ็กๅ ็ฝฎ็ฑปๅ
้ๅ็ฑปๅ
่ชๅฎไน็ฑปๅ
็ผ็จ่ฏญ่จ่ฏญๆณๆฆ่ฟฐ
่ฏๆณๅ ณ้ฎๅญๆซ็ฒ
้ป่พๅคๆญไธๅพช็ฏ
่ฏญๅฅไธ่กจ่พพๅผ
ไปฃ็ ่ดจ้๏ผๅผๅธธใๆต่ฏไธๆฅๅฟ
่ฐ่ฏ๏ผbdbไธpdb
Pythonๆ ๅๅบไธญ็Debuggerๆกๆถbdbๆจกๅ
ๆไพๅบๆฌ็่ฐ่ฏๅ่ฝ๏ผๅฆ่ฎพ็ฝฎๆญ็นใ็ฎก็Debugger็ๆง่ก็ญใ
bdbๆจกๅ็็ปๆ๏ผ
- ๅผๅธธbdb.BdbQuit(Exception)
- ็ฑปclass bdb.Breakpoint
- ็ฑปclass bdb.Bdb(skip=None)
- ๆต่ฏ็ฑปclass Tdb(Bdb)
Failed with: TOML parsing error: expected an equals, found a newline at line 1 column 5
Original markdown input:
```admonish tip title='pdbๆฏbdb็ๅญ็ฑป
BdbๆฏPython Debugger็ๅบ็ฑป๏ผๅฎ้
ไฝฟ็จ็Python Debuggerๆฏๅ
ถๅญ็ฑปPdbใ
```
- def set_trace(): ่ฏฅๆนๆณ็จไปฅๅผๅฏ่ฐ่ฏใ
- def checkfuncname(b, frame)
- def effective(file, line, frame): ่ฏฅๆนๆณ็จไปฅ็กฎๅฎ็ธๅฏนไบ่ฏฅfile็่ฏฅline๏ผๅชไธชBreakpointๆๆใ
Python Debugger่ฐ่ฏๅจ
Python็ไธๆฌพไบคไบๅผ่ฐ่ฏๅจ๏ผๅฏไปฅ่ฎพ็ฝฎๆญ็นใๅๆญฅ่ฐ่ฏใๆฃๆฅๅ ๆ ใ
pdbๆจกๅไธญ็Pdb็ฑป
class Pdb(bdb.Bdb, cmd.Cmd)
ๅฏๅจ่ฐ่ฏ็ๆนๅผ
- Python่งฃ้ๅจ็ๅฝไปค่กไธญ
# python3
import pdb
pdb.run('mymodule.mytest()')
- ่ฐ่ฏไธไธช่ๆฌๆไปถ
python3 -m pdb myscript.py
- ๅจPythonๆบไปฃ็ ไธญ
import pdb;
pdb.set_trace()
# ...
pdb.pm()
# ่ฟๅ
ฅ่ฐ่ฏๆจกๅผ
่ฐ่ฏๅฝไปค
-
h,ๅธฎๅฉ
-
w,ๆๅฐๅ ๆ
-
d,ๅจๅ ๆ ไธญ็งปๅจๅฐไธไธ็บงframe
-
u,ๅจๅ ๆ ไธญ็งปๅจๅฐไธไธ็บงframe
-
b lineno|func,ๅจๆๅฎไฝ็ฝฎๅค่ฎพ็ฝฎๆญ็น
-
tbreak lineno|func,ๅจๆๅฎไฝ็ฝฎๅค่ฎพ็ฝฎไธดๆถๆญ็น๏ผๆง่กๆถๆญ็นๅช็ๆไธๆฌก
-
disable bp_number,็ฆ็จๆๅฎๆญ็น
-
enable bp_number,ๅฏๅจๆๅฎๆญ็น
-
ignore bp_number count,ๅฟฝ็ฅๆๅฎๆญ็นcountๆฌก
-
cl,ๆธ ้คๆๆๆญ็น
-
cl lineno|func|bp_number,ๆธ ้คๆๅฎไฝ็ฝฎๅค็ๆญ็น
-
s,ๆง่กๅฝๅ่ก๏ผไธ่ฟๅ ฅ่ขซ่ฐ็จ็ๅฝๆฐ
-
n,ๆง่กๅฐไธไธ่ก๏ผๅฆๆ่ฐ็จไบๅ ถไปๅฝๆฐๅๆง่ก่ขซ่ฐ็จๅฝๆฐ
-
unt,ๆง่ก...็ดๅฐ
-
r,ๆง่กๅฐreturn
-
c,็ปง็ปญๆง่ก
-
j lineno,่ทณ่ฝฌๅฐๆๅฎ่ก
-
l,
-
ll,
-
a,
-
p ,
-
pp ,
-
whatis ,
-
source ,
-
display ,
-
undisplay ,
-
run,้ๅฏไปฃ็ ็ๆง่ก
-
restart,ๅrun
-
q,้ๅบ่ฐ่ฏๆจกๅผ
-
alias myname my_command,่ฎพ็ฝฎๅซๅ
-
้ๅธธๅจ.pdbrcๆไปถไธญ
-
unalias myname,ๅๆถๅซๅ
-
interact
ๅ่่ตๆบ๏ผ
- Python็่ฐ่ฏๆกๆถbdbๅ่ฐ่ฏๅจPdb_ๆ็ไธไธ็ๅๅฎข-CSDNๅๅฎข
- bdb โ Debugger framework โ Python 3.10.5 documentation
- pdb โ The Python Debugger โ Python 3.10.5 documentation
- cpython/pdb.py at 3.5 ยท python/cpython
- cpython/bdb.py at 3.5 ยท python/cpython
- Python็ๅผๅธธไฟกๆฏ่ฟ่ฝ่ฟๆ ทๅฑ็ฐ
่ฎพ่ฎกๆฝ่ฑก
็ผ็จ่ๅผ
ๅ่่ตๆบ
online-book
fragment
local
ๅฝๆฐๅผ็ผ็จ
ๅ่่ตๆบ
online-book
fragment
local
้ขๅๅฏน่ฑก็ผ็จ
ๅ่่ตๆบ
online-book
fragment
local
ๆณๅ็ผ็จ
ๅ่่ตๆบ
online-book
fragment
local
่ฎพ่ฎกๆจกๅผ
ๅ่่ตๆบ
online-book
fragment
local
้กน็ฎๆจกๅ็ฎก็ๅๆฉๅฑ
ๅฏนไบไธ้จ็ผ็จ่ฏญ่จ๏ผๆฏๅฆ่ฝๅคๆไธบๅทฅ็จๅๅผๅๅทฅๅ ท็ไธป่ฆๆ ๅๅจไบไธค็น๏ผ
- ๅ ็ฎก็ใๆจกๅ็ฎก็
- ๆฉๅฑๅทฅๅ ทๆฏๅฆๆนไพฟๅ ๅ ฅ
่ฟ้้ขๅ ๅซไธไบ้็จ็่ฎพ่ฎกๆฝ่ฑก๏ผๅ ๆญคไธ้จไฝไธบๅ็ฌ็ไธๅฑใ
ๅ่่ตๆบ
online-book
fragment
local
Pythonๆจกๅ็ณป็ป
package->module->method
package
ไธ็งๅฏๅ ๅซๅญๆจกๅๆ้ๅฝๅฐๅ ๅซๅญๅ ็ Python moduleใไปๆๆฏไธ่ฏด๏ผๅ ๆฏๅธฆๆ path ๅฑๆง็ Python ๆจกๅใ
ไผ ็ปๅ็ package๏ผไพๅฆๅ ๅซๆไธไธช init.py ๆไปถ็็ฎๅฝใ
PEP 420 ๆๅผๅ ฅ็ไธ็งไป ่ขซ็จไฝๅญๅ ็ๅฎนๅจ็ package๏ผๅฝๅ็ฉบ้ดๅ ๅฏไปฅๆฒกๆๅฎไฝ่กจ็คบ็ฉ๏ผๅ ถๆ่ฟฐๆนๅผไธ regular package ไธๅ๏ผๅ ไธบๅฎไปฌๆฒกๆ init.py ๆไปถใ
module
ๆญคๅฏน่ฑกๆฏ Python ไปฃ็ ็ไธ็ง็ป็ปๅไฝใๅๆจกๅๅ ทๆ็ฌ็ซ็ๅฝๅ็ฉบ้ด๏ผๅฏๅ ๅซไปปๆ Python ๅฏน่ฑกใๆจกๅๅฏ้่ฟ importing ๆไฝ่ขซๅ ่ฝฝๅฐ Python ไธญใ
ไธไธชๅฝๅ็ฉบ้ด๏ผๅ ถไธญๅ ๅซ็จไบๅ ่ฝฝๆจกๅ็็ธๅ ณๅฏผๅ ฅไฟกๆฏใๆฏ importlib.machinery.ModuleSpec ็ๅฎไพใ
- [importlib --- import ็ๅฎ็ฐ โ Python 3.10.5 ๆๆกฃ](https://docs.python.org/zh-cn/3/library/importlib.html#importlib.machinery.ModuleSpec)
ๅ
ณไบๆจกๅๅฏผๅ
ฅ็ณป็ป็ธๅ
ณ็ถๆ็่ง่ใ้ๅธธ่ฟๆฏไฝไธบๆจกๅ็ __spec__ ๅฑๆงๆด้ฒๅบๆฅใ
ๅจไปฅไธๆ่ฟฐไธญ๏ผๆฌๅท้็ๅๅญ็ปๅบไบๆจกๅๅฏน่ฑกไธญ็ดๆฅๅฏ็จ็ๅฑๆงใ
ๆฏๅฆ module.__spec__.origin == module.__file__ใ
ไฝๆฏ่ฏทๆณจๆ๏ผ่ฝ็ถ ๅผ ้ๅธธๆฏ็ธ็ญ็๏ผไฝๅฎไปฌๅฏไปฅไธๅ๏ผๅ ไธบไธคไธชๅฏน่ฑกไน้ดๆฒกๆ่ฟ่กๅๆญฅใ
ๅ ๆญค __path__ ๆๅฏ่ฝๅจ่ฟ่กๆถๅ่ฟๆดๆฐ๏ผ่่ฟไธไผ่ชๅจๅๆ ๅจ __spec__.submodule_search_locations ไธญใ
method
- ๆฏ่ฏญๅฏน็ ง่กจ: method resolution order โ Python 3.10.5 ๆๆกฃ ๆนๆณ่งฃๆ้กบๅบๅฐฑๆฏๅจๆฅๆพๆๅๆถๆ็ดขๅ จ้จๅบ็ฑปๆ็จ็ๅ ๅ้กบๅบ. ่ฏทๆฅ็ Python 2.3 ๆนๆณ่งฃๆ้กบๅบ ไบ่งฃ่ช 2.3 ็่ตท Python ่งฃๆๅจๆ็จ็ธๅ ณ็ฎๆณ็่ฏฆๆ ใ
- The Python 2.3 Method Resolution Order | Python.org
ๆจกๅ็็จๆ๏ผๅๅฒไธๅฏผๅ ฅ
ๅ่่ตๆบ
6. ๆจกๅ โ Python 3.10.5 ๆๆกฃ
- ๆไปถๅณๆจกๅ๏ผไธบๅฎ็ฐๅๅ้ๆฑ๏ผPython ๆๅ็งๅฎไนๅญๅ ฅไธไธชๆไปถ๏ผๅจ่ๆฌๆ่งฃ้ๅจ็ไบคไบๅผๅฎไพไธญไฝฟ็จใ่ฟไธชๆไปถๅฐฑๆฏ ๆจกๅ ๏ผๆจกๅไธญ็ๅฎไนๅฏไปฅ ๅฏผๅ ฅ ๅฐๅ ถไปๆจกๅๆ ไธป ๆจกๅ๏ผๅจ้กถๅฑๅ่ฎก็ฎๅจๆจกๅผไธ๏ผๆง่ก่ๆฌไธญๅฏ่ฎฟ้ฎ็ๅ้้๏ผใ
ๅจๆจกๅ่ฟไธ็น๏ผpythonใrustๅgoๅๆไธๅ
- python็ไปฃ็ ็ฎก็ๆๅฐๅไฝๆฏๆจกๅ
- rustไปฃ็ ็ฎก็ๆๅฐๅไฝไนๆฏๆจกๅ๏ผไฝๆฏๅฎ่ฟๆไพไบไธไธชๅ ณ้ฎๅญmod่ฎฉไธไธชๆไปถ้้ขๅ ๅซๅคไธชๆจกๅใrust็crateๅ ถๅฎๆฏ'ๆ ๅ'ๅ ๏ผ็ฑไธ็ณปๅๅทฒๅๅธใ็ๆฌๅใ่ขซๅๅ็ๅ ๆๆใๅฏไปฅ็ดๆฅไป็ๆฌๆงๅถไปๅบๆcrate.ioไธ่ฝฝๆจกๅใ
- go็moduleๅpackage็ๅ ณ็ณปๅไธๅไธค่ ๅ่ฟๆฅ๏ผๆจกๅ็ฑไธ็ณปๅๅทฒๅๅธใ็ๆฌๅใ่ขซๅๅ็ๅ ๆๆใๅฏไปฅ็ดๆฅไป็ๆฌๆงๅถไปๅบๆๆจกๅไปฃ็ๆๅกๅจไธ่ฝฝๆจกๅใ
- ๆไปถๅๅณๆจกๅๅ๏ผๆจกๅๆฏๅ ๅซ Python ๅฎไนๅ่ฏญๅฅ็ๆไปถใๅ ถๆไปถๅๆฏๆจกๅๅๅ ๅ็ผๅ .py ใ
- ๅจๆจกๅๅ ้จ๏ผ้่ฟๅ จๅฑๅ้ name ๅฏไปฅ่ทๅๆจกๅๅ๏ผๅณๅญ็ฌฆไธฒ๏ผใ
- ๅ ณไบๆจกๅๅฝๅ็ฉบ้ด๏ผๆฏไธชๆจกๅๆๅ่ชๆไปถ่ๅดๅ ็ๅ จๅฑๅฝๅ็ฉบ้ด(global namespace)
- ๆจกๅ้กถ้จๅผๅ ฅ็ๅ ถไปๆจกๅๅจๆไปถๅ ๅ จๅฑๅฏ็จ๏ผๅจๅฝๆฐใ็ฑป็ญๅ ้จๅผๅ ฅ็๏ผๅช่ฝๅจๅ ้จไฝฟ็จ
- ๅ ณไบfrom module_name import *: ๅฏผๅ ฅๆๆไธไปฅไธๅ็บฟ๏ผ_๏ผๅผๅคด็ๅ็งฐ
ๅคงๅคๆฐๆ ๅตไธ๏ผไธ่ฆ็จ่ฟไธชๅ่ฝ๏ผ่ฟ็งๆนๅผๅ่งฃ้ๅจๅฏผๅ ฅไบไธๆนๆช็ฅ็ๅ็งฐ๏ผๅฏ่ฝไผ่ฆ็ๅทฒ็ปๅฎไน็ๅ็งฐใ
- ๅ ณไบๅฏผๅ ฅๆถๅ็็ไบๆ ๏ผ
- ๅฝไธไธชๅไธบ spam ็ๆจกๅ่ขซๅฏผๅ ฅๆถ๏ผ่งฃ้ๅจ้ฆๅ ๆ็ดขๅ ทๆ่ฏฅๅ็งฐ็ๅ ็ฝฎๆจกๅใ
- ่ฟไบๆจกๅ็ๅๅญ่ขซๅๅจ sys.buildin_module_names ไธญใ
- ๅฆๆๆฒกๆๆพๅฐ๏ผๅฎๅฐฑๅจๅ้ sys.path ็ปๅบ็็ฎๅฝๅ่กจไธญๆ็ดขไธไธชๅไธบ spam.py ็ๆไปถใ
- sys.path ไป่ฟไบไฝ็ฝฎๅๅงๅ:
- ่พๅ ฅ่ๆฌ็็ฎๅฝ๏ผๆๆชๆๅฎๆไปถๆถ็ๅฝๅ็ฎๅฝ๏ผใ
- PYTHONPATH ๏ผ็ฎๅฝๅ่กจ๏ผไธ shell ๅ้ PATH ็่ฏญๆณไธๆ ท๏ผใ
- ไพ่ตไบๅฎ่ฃ ็้ป่ฎคๅผ๏ผๆ็ งๆฏไพๅ ๆฌไธไธช site-packages ็ฎๅฝ๏ผ็ฑ site ๆจกๅๅค็๏ผใ
- ๅ ณไบ'็ผ่ฏ'ๆไปถๅค็๏ผ 6. ๆจกๅ โ Python 3.10.5 ๆๆกฃ
- ๆพไธๅฐๆจกๅๆถ็ๅค็ๆญฅ้ชค๏ผ
- ไฝฟ็จdir()ๅฝๆฐ็กฎ่ฎคๆ็ดข่ทฏๅพ
- ๅฆๆๆฒกๆพๅฐ๏ผไฝฟ็จsys.pathๅฐๅฏนๅบ่ทฏๅพๅ ๅ ฅ
dir()ๅฝๆฐๅๅบไผๆๆ็ฑปๅ็ๅ็งฐ๏ผๅ้ใๆจกๅใๅฝๆฐ็ญใไฝไธไผๅๅบๅ ็ฝฎๅฝๆฐๅๅ้็ๅ็งฐใ่ฟไบๅ ๅฎน็ๅฎไนๅจๆ ๅๆจกๅ builtins ้
- ๅ ๆฏๆจกๅ็้ๅ๏ผๅญๅจๅฝขๅผๆฏ็ฎๅฝใๅฏผๅ ฅๅ ๆถ๏ผPython ๆ็ดข sys.path ้็็ฎๅฝ๏ผๆฅๆพๅ ็ๅญ็ฎๅฝใ
- ๅ ็ๆ ๅฟ: ๅฟ ้กปๆ__path__ๅฑๆง๏ผๅ ๅซ__init__.py
- ๅ ็ๅ็ฑป๏ผ
- ไผ ็ปๅ (regular package): ๅ ๅซไธไธช__init__.py
ๅฏผๅ ฅๅ ็ๆถๅ๏ผๆ้ป่ฎคๆง่ก__init__.py้้ข็ไปฃ็
- ๅฝๅ็ฉบ้ดๅ (namespace package): ไธ็งไป ่ขซ็จไฝๅญๅ ็ๅฎนๅจ็ package๏ผๅฝๅ็ฉบ้ดๅ ๅฏไปฅๆฒกๆๅฎไฝ่กจ็คบ็ฉ, ๆฒกๆ__init__.py
- ไปๅ ๅฏผๅ ฅ*
- ๅจๆไปถ็ณป็ปๆฅๆพๅนถๅฏผๅ ฅๅ ็ๆๆๅญๆจกๅใ่ฟ้กนๆไฝ่ฑ่ดน็ๆถ้ด่พ้ฟ๏ผๅนถไธๅฏผๅ ฅๅญๆจกๅๅฏ่ฝไผไบง็ไธๅฟ ่ฆ็ๅฏไฝ็จ๏ผ่ฟ็งๅฏไฝ็จๅชๆๅจๆพๅผๅฏผๅ ฅๅญๆจกๅๆถๆไผๅ็ใ
- ๅฏไปฅๅจ__init__.py้้ขไฝฟ็จ__all__ๅฎไน้ป่ฎคๅฏไปฅ่ขซๅฏผๅ ฅ็ๆจกๅ
- ๅ ็__path__ๅฑๆง๏ผๅจๅฏผๅ ฅๅ ็ๆถๅ๏ผๆง่ก__init__.pyไนๅ๏ผไผ้ป่ฎคๅฐ่ฟไธชๅฑๆง่ฟ่กๅๅงๅใไธป่ฆๆฏๅฐๅฝๅๅฏผๅ ฅๅ ็็ฎๅฝๆพๅ ฅๆ็ดข่ทฏๅพ้้ข
5. ๅฏผๅ ฅ็ณป็ป โ Python 3.10.5 ๆๆกฃ
่ฐ็จๅฏผๅ ฅๆบๅถ็ๆนๅผ
- import่ฏญๅฅ/import()
- importlib.import_module
importlib ๆจกๅๆไพไบไธไธชไธฐๅฏ็ API ็จๆฅไธๅฏผๅ ฅ็ณป็ป่ฟ่กไบคไบใ ไพๅฆ importlib.import_module() ๆไพไบ็ธๆฏๅ ็ฝฎ็ import() ๆดๆจ่ใๆด็ฎๅ็ API ็จๆฅๅ่ตท่ฐ็จๅฏผๅ ฅๆบๅถใ
ๆดๅค็ป่่ฏทๅ็ importlib ๅบๆๆกฃ:
ๅฏผๅ ฅๆจกๅๅ็ไบไปไน
- ๅฝไธไธชๆจกๅ้ฆๆฌก่ขซๅฏผๅ ฅๆถ๏ผPython ไผๆ็ดข่ฏฅๆจกๅ
- ๅฆๆๆพๅฐๅฐฑๅๅปบไธไธช module ๅฏน่ฑก 1 ๅนถๅๅงๅๅฎใ
- ๅฆๆๆๅฎๅ็งฐ็ๆจกๅๆชๆพๅฐ๏ผๅไผๅผๅ ModuleNotFoundErrorใ
- ๅฝๅ่ตท่ฐ็จๅฏผๅ ฅๆบๅถๆถ๏ผPython ไผๅฎ็ฐๅค็ง็ญ็ฅๆฅๆ็ดขๆๅฎๅ็งฐ็ๆจกๅใ
่ฟไบ็ญ็ฅๅฏไปฅ้่ฟไฝฟ็จไฝฟ็จไธๆๆๆ่ฟฐ็ๅค็ง้ฉๅญๆฅๅ ไปฅไฟฎๆนๅๆฉๅฑใ
ๅจ 3.3 ็ๆดๆน: ๅฏผๅ ฅ็ณป็ปๅทฒ่ขซๆดๆฐไปฅๅฎๅ จๅฎ็ฐ PEP 302 ไธญ็็ฌฌไบ้ถๆฎต่ฆๆฑใ ไธไผๅๆไปปไฝ้ๅผ็ๅฏผๅ ฅๆบๅถ โโ ๆดไธชๅฏผๅ ฅ็ณป็ป้ฝ้่ฟ sys.meta_path ๆด้ฒๅบๆฅใ ๆญคๅค๏ผๅฏนๅ็ๅฝๅ็ฉบ้ดๅ ็ๆฏๆไนๅทฒ่ขซๅฎ็ฐ (ๅ่ง PEP 420)ใ
python็ๆจกๅ
Python ๅชๆไธ็งๆจกๅๅฏน่ฑก็ฑปๅ๏ผๆๆๆจกๅ้ฝๅฑไบ่ฏฅ็ฑปๅ๏ผๆ ่ฎบๆจกๅๆฏ็จ PythonใC ่ฟๆฏๅซ็่ฏญ่จๅฎ็ฐใ
python็ๅ
ไธบไบๅธฎๅฉ็ป็ปๆจกๅๅนถๆไพๅ็งฐๅฑๆฌก็ปๆ๏ผPython ่ฟๅผๅ ฅไบ ๅ ็ๆฆๅฟตใ
ไฝ ๅฏไปฅๆๅ ็ๆๆฏๆไปถ็ณป็ปไธญ็็ฎๅฝ๏ผๅนถๆๆจกๅ็ๆๆฏ็ฎๅฝไธญ็ๆไปถ
ๅ ไธบๅ ๅๆจกๅไธๆฏๅฟ ้กปๆฅ่ชไบๆไปถ็ณป็ปใ ไธบไบๆนไพฟ็่งฃๆฌๆๆกฃ๏ผๆไปฌๅฐ็ปง็ปญไฝฟ็จ่ฟ็ง็ฎๅฝๅๆไปถ็็ฑปๆฏใ ไธๆไปถ็ณป็ปไธๆ ท๏ผๅ ้่ฟๅฑๆฌก็ปๆ่ฟ่ก็ป็ป๏ผๅจๅ ไนๅ ้คไบไธ่ฌ็ๆจกๅ๏ผ่ฟๅฏไปฅๆๅญๅ ใ
ๅฏนๆฏ่็ณปๅ ๅๆจกๅ
่ฆๆณจๆ็ไธไธช้็นๆฆๅฟตๆฏๆๆๅ ้ฝๆฏๆจกๅ๏ผไฝๅนถ้ๆๆๆจกๅ้ฝๆฏๅ ใ ๆ่ ๆขๅฅ่ฏ่ฏด๏ผๅ ๅชๆฏไธ็ง็นๆฎ็ๆจกๅใ ็นๅซๅฐ๏ผไปปไฝๅ ทๆ path ๅฑๆง็ๆจกๅ้ฝไผ่ขซๅฝไฝๆฏๅ ใ
ๆๆๆจกๅ้ฝๆ่ชๅทฑ็ๅๅญใ ๅญๅ ๅไธๅ ถ็ถๅ ๅไผไปฅ็นๅทๅ้๏ผไธ Python ็ๆ ๅๅฑๆง่ฎฟ้ฎ่ฏญๆณไธ่ดใ
ๅ ็ๅ็ฑป
ๅธธ่งๅ
- ๅ ๅซ__init__.pyๆไปถ๏ผไผๅจๅฏผๅ ฅๆถ้ๅผๆง่ก
- ๅฆๆๆฒกๆ__init__.py, ไธไธชๅ ๅซๆไปถ็็ฎๅฝไนๆฏไผ่ขซ่ฎคไธบๆฏไธไธชๅ , ๅฝๅ็ฉบ้ดๅ
parent/
__init__.py
one/
__init__.py
two/
__init__.py
three/
__init__.py
import parent.one
- ๅฏผๅ ฅ parent.one ๅฐ้ๅผๅฐๆง่ก parent/init.py ๅ parent/one/init.pyใ
- ๅ็ปญๅฏผๅ ฅ parent.two ๆ parent.three ๅๅฐๅๅซๆง่ก parent/two/init.py ๅ parent/three/init.pyใ
ๅฝๅ็ฉบ้ดๅ
- ๅฝๅ็ฉบ้ดๅ ไธๅ ๅซ__init__.py, ่ฟๆ ทๅฐฑไธไผ้ๅฎๆฏๅไธชๅ ๅ ็ๆจกๅๅ็งฐ
- ไธๅ ๅซ__init__.py็ๆถๅ๏ผไธๅ็ฎๅฝไธ็ๅๅๅ ไผ่ขซ่ฎคไธบๆฏๅไธไธชๅ ใ
่ฟไธ็นๅฏไปฅๅgolang็ๅ ๆบๅถๅฏนๆฏ่็ณป่ตทๆฅ
ๅฝๅๅ ็ๅฝๅ็ฉบ้ด, ไธคไธชไธๅ็ๅ ็ฎๅฝ่ขซๅๅนถๅฐไธ่ตท๏ผไฝ ๅฏไปฅๅฏผๅ ฅspam.blahๅspam.grok๏ผๅนถไธๅฎไปฌ่ฝๅคๅทฅไฝใ
foo-package/
spam/
blah.py
bar-package/
spam/
grok.py
>>> import sys
>>> sys.path.extend(['foo-package', 'bar-package'])
>>> import spam.blah
>>> import spam.grok
>>>
ๆ็ดข
ๅ ่ฝฝ
็ธๅฏนๅฏผๅ ฅ
package/
__init__.py
subpackage1/
__init__.py
moduleX.py
moduleY.py
subpackage2/
__init__.py
moduleZ.py
moduleA.py
- ไฝฟ็จ"."็ธๅฏนๅฏผๅ ฅ
from .moduleY import spam
from .moduleY import spam as ham
from . import moduleY
from ..subpackage1 import moduleY
from ..subpackage2.moduleZ import eggs
from ..moduleA import foo
- ่ฟๅฏไปฅไธปๅจๆทปๅ ๆ็ดข่ทฏๅพๅๅฏผๅ ฅ
# moduleX.py
import sys
sys.append('..')
from moduleA import *
ไปปๅกๆฝ่ฑก
ๅ่่ตๆบ
online-book
fragment
local
ๅนถๅ
ๅ่่ตๆบ
online-book
fragment
local
ไปIOๆจกๅๅผๅง
- ไปIOๆจกๅๅผๅง
1. ๅๆญฅ/ๅผๆญฅใ้ปๅก/้้ปๅกๆฆๅฟตๅบๅซ
ๅๆญฅๅๅผๆญฅ๏ผๅ ณๆณจ็ๆฏๆถๆฏ้ไฟกๆบๅถใ๏ผ่ฐ็จ่ ่ง่ง๏ผ
- ๅๆญฅ๏ผๅๅบไธไธช่ฐ็จ๏ผๅจๆฒกๆๅพๅฐ็ปๆไนๅไธ่ฟๅใ
- ๅผๆญฅ๏ผๅๅบไธไธช่ฐ็จ๏ผๅจๆฒกๆๅพๅฐ็ปๆไนๅ่ฟๅใ
้ปๅกๅ้้ปๅก๏ผๅ ณๆณจ็ๆฏ็จๅบ็ญๅพ ่ฐ็จ็ปๆ็็ถๆใ๏ผ่ขซ่ฐ็จ่ ่ง่ง๏ผ
- ้ปๅก๏ผๅจ่ฐ็จ็ปๆ่ฟๅไนๅ๏ผ็บฟ็จ่ขซๆ่ตทใ
- ้้ปๅก๏ผๅจ่ฐ็จ็ปๆ่ฟๅไนๅ๏ผ็บฟ็จไธไผ่ขซๆ่ตทใ
้ปๅก๏ผไธ็ณป็ป่ฐ็จๆๅ ณใ
2. ๅๆญฅ/ๅผๆญฅIO ๆจกๅๅ็ฑป
+-+ ้ป ๅก I/O (BIO)
|
+-+ ้ ้ป ๅก I/O (NIO)
|
+----+ ๅ ๆญฅ I/O +--+
| |
| +-+ I/O ๅค ่ทฏ ๅค ็จ
| |
| +-+ ไฟก ๅท ้ฉฑ ๅจ I/O
I/O ๆจก ๅ +---+
|
|
| +-+ Linux (AIO)
| | (io_uring)
+----+ ๅผ ๆญฅ I/O +--+
|
+-+ windows (IOCP)
3. ๅๆญฅ้ปๅกI/O (blocking I/O)
Application kernel
+---------+ +-----------+ +---+
| | syscall | no | |
| Read | +--------> | datagram | |
| recvfrom| | ready | |
| | | + | +-+ wait for
| | | | | +-+ data
| | | v | |
| | | datagram | |
| | | ready | +---+
| | | |
| | | copy | +---+
| | | datagram | |
|process | | + | +-+ copy data
|datagram | return | | | +-+ from kernel to user
| | <--------+ | v | |
| | | copy | +---+
| | | complete |
+---------+ +-----------+
่พๅ ฅๆไฝไธคไธช้ถๆฎต๏ผ
- ่ฟ็จ็ญๅพ
ๅ
ๆ ธๆๆฐๆฎๅๅคๅฅฝ๏ผ่ฟไธช้ถๆฎตๅฏไปฅ้ปๅกไนๅฏ้้ปๅก๏ผ่ฎพ็ฝฎsocketๅฑๆงใ
- ้ปๅก๏ผ recvfrom ้ปๅก็บฟ็จ็ดๅฐ่ฟๅๆฐๆฎๅฐฑ็ปช็็ปๆใ
- ้้ปๅก๏ผ็ซๅณ่ฟๅไธไธช้่ฏฏ๏ผ่ฝฎ่ฏข็ดๅฐๆฐๆฎๅฐฑ็ปชใ
- ไปๅ ๆ ธ็ผๅฒๅบๅ่ฟ็จ็ผๅฒๅบๅคๅถๆฐๆฎใ๏ผไธ็ด้ปๅก๏ผ
ๅผๆญฅI/O๏ผrecvfromๆปๆฏ็ซๅณ่ฟๅ๏ผไธคไธช้ถๆฎต้ฝ็ฑๅ ๆ ธๅฎๆใ
4. I/O ๅค่ทฏๅค็จ๏ผI/O Multiplexing )
IOๅค่ทฏๅค็จๆฏไธ็งๅๆญฅIOๆจกๅ๏ผๅฎ็ฐไธไธช็บฟ็จๅฏไปฅ็่งๅคไธชๆไปถๅฅๆใ
ๆฏๆI/Oๅค่ทฏๅค็จ็็ณป็ป่ฐ็จๆ select/pselect/poll/epoll๏ผๆฌ่ดจ้ฝๆฏๅๆญฅI/O๏ผๅ ไธบๆฐๆฎๆท่ด้ฝๆฏ้ปๅก็ใ ้่ฟ select/epoll ๆฅๅคๆญๆฐๆฎๆฅๆฏๅฆๅๅคๅฅฝ๏ผๅณๅคๆญๅฏ่ฏปๅฏๅ็ถๆใ
5. epoll: ๅๆญฅ้ปๅก/้้ปๅกๆจกๅ
+--------------------------------+ +-------------------------+
| epoll_ctl | | epoll_wait |
| | | |
| | | +----+ |
| +---+ | | | | |
| | | | | | | |
| +-+---+--+ | | +--+-+ |
| | | | | | |
| +--++ +-++ | | | |
epoll_create +----> | | | | | | | +--+-+ |
| +-+-+ +--+ +---->+ | | |
| | |event| | | |
| +----+--+ | | +--+-+ |
| | | | | | |
| ++ | | | | |
| +--+ +-+-+ | | +--+-+ |
| | | | | | | | | |
| +--+ +---+ | | | | |
| | | +----+ |
| ็บข ้ป ๆ | | ้พ ่กจ |
+--------------------------------+ +-------------------------+
epollไธไธชๅฝๆฐ
- epoll_create(int size) : ๅ ๆ ธไบง็ไธไธชepollๅฎไพๆฐๆฎ็ปๆ๏ผๅนถ่ฟๅไธไธชepfd
- epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)๏ผๅฐ่ขซ็ๅฌ็ๆ่ฟฐ็ฌฆๆทปๅ ๅฐ็บข้ปๆ ๆไป็บข้ปๆ ไธญๅ ้คๆ่ ๅฏน็ๅฌไบไปถ่ฟ่กไฟฎๆนใ
- epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout): ้ปๅก็ญๅพ ๆณจๅ็ไบไปถๅ็๏ผ่ฟๅไบไปถ็ๆฐ็ฎ๏ผๅนถๅฐ่งฆๅ็ไบไปถๅๅ ฅeventsๆฐ็ปไธญ
epoll ไธค็ง่งฆๅๆบๅถ๏ผ
- ๆฐดๅนณ่งฆๅๆบๅถ๏ผLT)ใ็ผๅฒๅบๅช่ฆๆๆฐๆฎๅฐฑ่งฆๅ่ฏปๅใepoll ้ป่ฎคๅทฅไฝๆนๅผใselect/pollๅชๆฏๆ่ฏฅๆนๅผใ
- ่พน็ผ่งฆๅๆบๅถ๏ผET)ใ็ผๅฒๅบ็ฉบๆๆปก็็ถๆๆ่งฆๅ่ฏปๅใnginx ไฝฟ็จ่ฏฅๆนๅผ๏ผ้ฟๅ ้ข็น่ฏปๅใ
ๆ็พค้ฎ้ข๏ผ
ๅฝๅคไธช่ฟ็จ/็บฟ็จ่ฐ็จepoll_waitๆถไผ้ปๅก็ญๅพ ๏ผๅฝๅ ๆ ธ่งฆๅๅฏ่ฏปๅไบไปถ๏ผๆๆ่ฟ็จ/็บฟ็จ้ฝไผ่ฟ่กๅๅบ๏ผไฝๆฏๅฎ้ ไธๅชๆไธไธช่ฟ็จ/็บฟ็จ็ๅฎๅค็่ฟไบไบไปถใ Liux 4.5 ้่ฟๅผๅ ฅ EPOLLEXCLUSIVE ๆ ่ฏๆฅไฟ่ฏไธไธชไบไปถๅ็ๆถๅๅชๆไธไธช็บฟ็จไผ่ขซๅค้๏ผไปฅ้ฟๅ ๅคไพฆๅฌไธ็ๆ็พค้ฎ้ขใ
6. ๅผๆญฅ I/O ๆจกๅ: io_uring
Linux AIO ๅฎ็ฐ็ๅนถไธ็ๆณ๏ผๆไปฅๅผๅ ฅไบๆฐ็ๅผๆญฅI/Oๆฅๅฃ io_uringใ
+----+ Head +---------+ +----------+ Head
| | | | |
| | | | |
| +---------+ +----------+
| | | | |
| | | | |
| +---------+ +----------+
| | | | |
| | | | |
| +---------+ +----------+
| | | | |
| Tail +---------+ +----------+ Tail <--+
| +--------------------------------------------+ |
| | Kernel | |
| | | |
| | +-------+ +-------+ | |
| | | | | | | |
+---------------> | SQ | | CQ | +--------+
| | | | | |
| +-------+ +-------+ |
| |
+--------------------------------------------+
io_uringๆฅๅฃ้่ฟไธคไธชไธป่ฆๆฐๆฎ็ปๆๅทฅไฝ๏ผ
- ๆไบค้ๅๆก็ฎ๏ผsqe๏ผ
- ๅฎๆ้ๅๆก็ฎ๏ผcqe๏ผ
่ฟไบ็ปๆ็ๅฎไพไฝไบๅ ๆ ธๅๅบ็จ็จๅบไน้ด็ๅ ฑไบซๅ ๅญๅ็ไบง่ ๅๆถ่ดน่ ็ฏๅฝข็ผๅฒๅบไธญใ
ๅ่๏ผ
https://thenewstack.io/how-io_uring-and-ebpf-will-revolutionize-programming-in-linux/
https://cor3ntin.github.io/posts/iouring/#io_uring
ๅ ไธบๅค็ I/O ๅค็จ็็ผ็จๆจกๅ็ธๅฝๅคๆ๏ผไธบไบ็ฎๅ็ผ็จ๏ผๅผๅ ฅไบไธ้ขไธค็งๆจกๅ:
1. Reactor๏ผๅๅบๅจ๏ผ ๆจกๅผ
ๅฏนๅบๅๆญฅI/O๏ผ่ขซๅจ็ไบไปถๅ็ฆปๅๅๅๆจกๅใๆๅก็ญๅพ ่ฏทๆฑไบไปถ็ๅฐๆฅ๏ผๅ้่ฟไธๅ้ดๆญ็ๅๆญฅๅค็ไบไปถ๏ผไป่ๅๅบๅๅบใ
2. Preactor๏ผไธปๅจๅจ๏ผ ๆจกๅผ
ๅฏนๅบๅผๆญฅI/O๏ผไธปๅจ็ไบไปถๅ็ฆปๅๅๅๆจกๅใ่ฟ็ง่ฎพ่ฎกๅ ่ฎธๅคไธชไปปๅกๅนถๅ็ๆง่ก๏ผไป่ๆ้ซๅๅ้๏ผๅนถๅฏๆง่ก่ๆถ้ฟ็ไปปๅก๏ผๅไธชไปปๅก้ดไบไธๅฝฑๅ๏ผใ
Reactor Model:
+----------------+
req Dispatch | |
+------+ +--------> | req handler |
| | | +----------------+
| | +----+ |
+------+ | event +------------+ |
| | | |
+--------> | Service | |Dispatch +----------------+
| Handler +------------> | |
req +---------> | | | | req handler |
+------+ | +------------+ | +----------------+
| | | event |
| +----+ |
+------+ | Dispatch +----------------+
+--------->+ |
| req handler |
+----------------+
ไธ็งๅฎ็ฐๆนๅผ๏ผ
- ๅ็บฟ็จๆจกๅผใ accept()ใread()ใwrite()ไปฅๅconnect()ๆไฝ ้ฝๅจๅไธ็บฟ็จใ
- ๅทฅไฝ่ ็บฟ็จๆฑ ๆจกๅผใ้ I/O ๆไฝไบค็ป็บฟ็จๆฑ ๅค็
- ๅค็บฟ็จๆจกๅผใไธปReactor (master) ๏ผ่ด่ดฃ็ฝ็ป็ๅฌ ๏ผ ๅญReactor(worker) ่ฏปๅ็ฝ็ปๆฐๆฎใ
่ฏปๅๆไฝๆต็จ๏ผ
- ๅบ็จๆณจๅ่ฏปๅๅฐฑ็ปชไบไปถๅ็ธๅ ณ่็ไบไปถๅค็ๅจ
- ไบไปถๅ็ฆปๅจ็ญๅพ ไบไปถๅ็
- ๅฝๅ็่ฏปๅๅฐฑ็ปชไบไปถ๏ผไบไปถๅ็ฆปๅจ่ฐ็จๅทฒๆณจๅ็ไบไปถๅค็ๅจ
- ไบไปถๅค็ๅจๆง่ก่ฏปๅๆไฝ
ๅไธ่ ๏ผ
- ๆ่ฟฐ็ฌฆ๏ผhandle๏ผ๏ผๆไฝ็ณป็ปๆไพ็่ตๆบ๏ผ่ฏๅซ socket็ญใ
- ๅๆญฅไบไปถๅค่ทฏๅ็ฆปๅจใๅผๅฏไบไปถๅพช็ฏ๏ผ็ญๅพ ไบไปถ็ๅ็ใๅฐ่ฃ ไบ ๅค่ทฏๅค็จๅฝๆฐ select/poll/epoll็ญใ
- ไบไปถๅค็ๅจใๆไพๅ่ฐๅฝๆฐ๏ผ็จไบๆ่ฟฐไธๅบ็จ็จๅบ็ธๅ ณ็ๆไธชไบไปถ็ๆไฝใ
- ๅ ทไฝ็ไบไปถๅค็ๅจใไบไปถๅค็ๅจๆฅๅฃ็ๅ ทไฝๅฎ็ฐใไฝฟ็จๆ่ฟฐ็ฌฆๆฅ่ฏๅซไบไปถๅ็จๅบๆไพ็ๆๅกใ
- Reactor ็ฎก็ๅจใไบไปถๅค็ๅจ็่ฐๅบฆๆ ธๅฟใๅ็ฆปๆฏไธชไบไปถ๏ผ่ฐๅบฆไบไปถ็ฎก็ๅจ๏ผ่ฐ็จๅ ทไฝ็ๅฝๆฐๅค็ๆไธชไบไปถใ
ๅ่่ตๆบ
online-book
fragment
local
ๅค็บฟ็จๅนถๅๆจกๅ
ๅ่่ตๆบ
online-book
fragment
local
ๅผๆญฅๆจกๅ
ๅ่่ตๆบ
online-book
fragment
local
ๅ ็ผ็จ
ๅ่่ตๆบ
online-book
fragment
local
ๅ่ฎฎๆฝ่ฑก
ๅ่่ตๆบ
online-book
fragment
local
ๅค่ฏญ่จ็ผ็จ
ๅ่่ตๆบ
online-book
fragment
local
่ฎก็ฎๆบ็ฝ็ป
ๅ่่ตๆบ
online-book
fragment
local
็ๆ็ณป็ป
ๅ่่ตๆบ
online-book
fragment
local
ๅญฆไน ่ตๆบ
ๅฎๆนๅจๆ
็คพๅบ็น็น
ๅญฆๆฏๅจๆ
ๅผๆบ่งๅฏ
ๅฝไปค่กๅทฅๅ ท
ๆฐๆฎๅค็
ๅตๅ ฅๅผ
ๆไฝ็ณป็ป
pythontutor้กน็ฎ่งฃๅ
่ฏดๆ
ๆฌๆไธป่ฆๅๆไธไธpythontutor็้กน็ฎ็ปๆไธไธๅกๆต็จ๏ผๅนถ็กฎๅฎๅ้ข็็ธๅ ณไปฃ็ ๅฏ่งๅ็ไฝฟ็จๆนๆณ
ๆปไฝ็ปๆๅพ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ _ _ โ
โ _ __ __ _ __| |____ _ __ _ ___ (_)___ ___ _ _ โ
โ | '_ \/ _` / _| / / _` / _` / -_)_ | (_-</ _ \ ' \ โ
โ | .__/\__,_\__|_\_\__,_\__, \___(_)/ /__/\___/_||_| โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ |_| |___/ |__/ โ
โ ___ _ _ _____ _ ___ โ โ โ
โ | _ \_ _| |_| |_ ___ _ _ |_ _| _| |_ ___ _ _ | __|_ _____ __ โ โ { โ
โ | _/ || | _| ' \/ _ \ ' \ | || || | _/ _ \ '_| | _|\ \ / -_) _| โ โ "name": "v5-unity", โ
โ |_| \_, |\__|_||_\___/_||_| |_| \_,_|\__\___/_| |___/_\_\___\__| โ โ "version": "1.0.0", โ
โ |__/ โ โ "description": "OPT v5", โ
โ โ โ "main": "bundle.js", โ
โ โ โ "repository": "https://github.com/pgbovine/OnlinePythonTutor", โ
โ โ โ "license": "BSD-3-Clause", โ
โ โ โ "scripts": { โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ "start": "python bottle_server.py", โ
โ โ โ โ โ "py3start": "python3 bottle_server.py", โ
โ โ botter_server.py โ โ โโโโโโโโโโโซ "webpack": "webpack --devtool sourcemap --progress --colors --watch", โ
โ โ get_py_exec โโโโโโโโโโโโโโ โ โ โ "production-build": "rm -f build/* && webpack && python โ
โ โ โ โ โ โ โ add_cache_busting_query_strings.py" โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ }, โ
โ โ โ โ โ "dependencies": { โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ "css-loader": "", โ
โ โโโโโโโโโโโโโถ โ โ npm run production-build โ "fs-extra": "^6.0.1", โ
โ โ pg_logger.py โ โ โ โ "json-stable-stringify": "^1.0.1", โ
โ โ exec_script_str_local โ โ โ โ "on-build-webpack": "^0.1.0", โ
โ โโโโโโโโโโโโโค โ โ โ โ "pixelmatch": "^4.0.2", โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ "puppeteer": "^1.5.0", โ
โ โ โ โ โ โ โ "script-loader": "", โ
โ โ โ โ /visualize.html โ โ โ "style-loader": "", โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโถ visualize.bundle.js โโโโโโโโโโ โ "ts-loader": "^3.5.0", โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ โ "url-loader": "" โ
โ โ โโโโโโโโโโโโโ return trace info โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ } โ
โ โ pg_logger.py โ {code: '', trace: []} โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฒโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ PGLogger._runscript โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ webpack
โ โ โ
โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโปโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ _ _ __ _ _ โ
โ โ โ __ __ _____| |__ _ __ __ _ __| |__ __ ___ _ _ / _(_)__ _ (_)___ โ
โ โ โ \ V V / -_) '_ \ '_ \/ _` / _| / /_/ _/ _ \ ' \| _| / _` |_ | (_-< โ
โ โ โ \_/\_/\___|_.__/ .__/\__,_\__|_\_(_)__\___/_||_|_| |_\__, (_)/ /__/ โ
โ โ โ |_| |___/ |__/ โ
โ โ โ entry: { โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ 'visualize': "./js/visualize.ts", โ
โ 'recorder': "./js/recorder.ts", โ
โ 'render-trace': "./js/render-trace.ts", โ
โ 'opt-live': "./js/opt-live.ts", โ
โ 'iframe-embed': "./js/iframe-embed.ts", โ
โ 'index': "./js/index.ts", โ
โ 'composingprograms': "./js/composingprograms.ts", โ
โ 'csc108h': "./js/csc108h.ts", โ
โ 'pytutor-embed': "./js/pytutor-embed.ts", โ
โ }, โ
โ โ
โ output: { โ
โ path: __dirname + "/build/", โ
โ // TODO: use 'bundle.[hash].js' for fingerprint hashing โ
โ // to create unique filenames for releases: โ
โ // https://webpack.github.io/docs/long-term-caching.html โ
โ filename: "[name].bundle.js", โ
โ sourceMapFilename: "[file].map", โ
โ }, โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
iframeไฝฟ็จ็คบไพ
ไฝฟ็จbottleๅwebๆๅก
from bottle import route, get, request, run, template, static_file
try:
import StringIO # NB: don't use cStringIO since it doesn't support unicode!!!
except:
import io as StringIO # py3
import json
import pg_logger
@route('/web_exec_<name:re:.+>.py')
@route('/LIVE_exec_<name:re:.+>.py')
@route('/viz_interaction.py')
@route('/syntax_err_survey.py')
@route('/runtime_err_survey.py')
@route('/eureka_survey.py')
@route('/error_log.py')
def dummy_ok(name=None):
return 'OK'
@route('/<filepath:path>')
def index(filepath):
return static_file(filepath, root='.')
# Note that this will run either Python 2 or 3, depending on which
# version of Python you used to start the server, REGARDLESS of which
# route was taken:
@route('/web_exec_py2.py')
@route('/web_exec_py3.py')
@route('/LIVE_exec_py2.py')
@route('/LIVE_exec_py3.py')
def get_py_exec():
out_s = StringIO.StringIO()
def json_finalizer(input_code, output_trace):
ret = dict(code=input_code, trace=output_trace)
json_output = json.dumps(ret, indent=None)
out_s.write(json_output)
options = json.loads(request.query.options_json)
pg_logger.exec_script_str_local(request.query.user_script,
request.query.raw_input_json,
options['cumulative_mode'],
options['heap_primitives'],
json_finalizer)
return out_s.getvalue()
if __name__ == "__main__":
run(host='localhost', port=8003, reloader=True)
่ฟ้ๅฏไปฅๅ็ฐ๏ผไฝ่ ็่ทฏ็ฑๅบๆฌๆฑ่ๅจget_py_exec, ่ฟๅ ฅๅๆง่กexec_script_str_local
pg_logger.pyไป็ป
โโโโโโโโโโโโโโโโโโโโโ
โ โ
โ botter_server.py โ
โ get_py_exec โโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโ โ
โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโถ โ
โ pg_logger.py โ
โ exec_script_str_local โ
โโโโโโโโโโโโโค โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโ
โ pg_logger.py โ
โ PGLogger._runscript โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
็ปงๆฟ่ชBdb
class PGLogger(bdb.Bdb):
ๅๅงๅ็ธๅ ณ
def __init__(
self,
cumulative_mode,
heap_primitives,
show_only_outputs,
finalizer_func,
disable_security_checks=False,
allow_all_modules=False,
crazy_mode=False,
custom_modules=None,
separate_stdout_by_module=False,
probe_exprs=None):
่ฐ็จๅฝๆฐ
def exec_script_str_local(
script_str,
raw_input_lst_json,
cumulative_mode,
heap_primitives,
finalizer_func,
probe_exprs=None,
allow_all_modules=False):
# ๆ ธๅฟ่ฟ่ก่ฟ็จ่ฎฐๅฝ็ฑป
logger = PGLogger(
cumulative_mode,
heap_primitives,
False,
finalizer_func,
disable_security_checks=True,
allow_all_modules=allow_all_modules,
probe_exprs=probe_exprs
)
# TODO: refactor these NOT to be globals
global input_string_queue
input_string_queue = []
if raw_input_lst_json:
# TODO: if we want to support unicode, remove str() cast
input_string_queue = [str(e) for e in json.loads(raw_input_lst_json)]
try:
logger._runscript(script_str)
except bdb.BdbQuit:
pass
finally:
return logger.finalize()
่ฟๅๆฐๆฎ็คบไพ
{
"code": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())",
"trace": [
{
"line": 5,
"event": "step_line",
"func_name": "<module>",
"globals": {},
"ordered_globals": [],
"stack_to_render": [],
"heap": {},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 19,
"event": "step_line",
"func_name": "<module>",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [],
"heap": {},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 10,
"event": "call",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601"
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 11,
"event": "step_line",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601"
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 12,
"event": "step_line",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"name",
"Pat"
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 13,
"event": "step_line",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"name",
"Pat"
],
[
"role",
"Professor"
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 14,
"event": "step_line",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 14,
"event": "return",
"func_name": "__init__",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
]
},
"ordered_globals": [
"Staff601"
],
"stack_to_render": [
{
"func_name": "__init__",
"is_parent": false,
"frame_id": 1,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"name": "Pat",
"role": "Professor",
"years": 60,
"salary": 100000,
"__return__": null
},
"ordered_varnames": [
"self",
"name",
"role",
"years",
"salary",
"__return__"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "__init___f1"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 20,
"event": "step_line",
"func_name": "<module>",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
],
"pat": [
"REF",
1
]
},
"ordered_globals": [
"Staff601",
"pat"
],
"stack_to_render": [],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 16,
"event": "call",
"func_name": "salutation",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
],
"pat": [
"REF",
1
]
},
"ordered_globals": [
"Staff601",
"pat"
],
"stack_to_render": [
{
"func_name": "salutation",
"is_parent": false,
"frame_id": 2,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
]
},
"ordered_varnames": [
"self"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "salutation_f2"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 17,
"event": "step_line",
"func_name": "salutation",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
],
"pat": [
"REF",
1
]
},
"ordered_globals": [
"Staff601",
"pat"
],
"stack_to_render": [
{
"func_name": "salutation",
"is_parent": false,
"frame_id": 2,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
]
},
"ordered_varnames": [
"self"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "salutation_f2"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 17,
"event": "return",
"func_name": "salutation",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
],
"pat": [
"REF",
1
]
},
"ordered_globals": [
"Staff601",
"pat"
],
"stack_to_render": [
{
"func_name": "salutation",
"is_parent": false,
"frame_id": 2,
"parent_frame_id_list": [],
"encoded_locals": {
"self": [
"REF",
1
],
"__return__": "Professor Pat"
},
"ordered_varnames": [
"self",
"__return__"
],
"is_zombie": false,
"is_highlighted": true,
"unique_hash": "salutation_f2"
}
],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\n"
},
{
"line": 20,
"event": "return",
"func_name": "<module>",
"globals": {
"Staff601": [
"IMPORTED_FAUX_PRIMITIVE",
"imported class"
],
"pat": [
"REF",
1
]
},
"ordered_globals": [
"Staff601",
"pat"
],
"stack_to_render": [],
"heap": {
"1": [
"INSTANCE",
"Staff601",
[
"age",
60
],
[
"name",
"Pat"
],
[
"role",
"Professor"
],
[
"salary",
100000
]
]
},
"stdout": "# The __init__ 'constructor' - object-oriented programming intro\n# Adapted from MIT 6.01 course notes (Section 3.5)\n# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf\n\nclass Staff601:\n course = '6.01'\n building = 34\n room = 501\n\n def __init__(self, name, role, years, salary):\n self.name = name\n self.role = role\n self.age = years\n self.salary = salary\n\n def salutation(self):\n return self.role + ' ' + self.name\n\npat = Staff601('Pat', 'Professor', 60, 100000)\nprint(pat.salutation())\nProfessor Pat\n"
}
]
}
ๅ่่ตๆ
- KuanHsiaoKuo/OnlinePythonTutor
- KuanHsiaoKuo/PythonTutorService: ๅบไบOnlinePythonTutorๅผๆบ้กน็ฎ่ฟ่กๆนๅ
- bdbไธpdbไป็ป
- Online Python Tutor- Embeddable Web-Based Program Visualization for CS Education.pdf
- Online python tutor: embeddable web-based program visualization for cs education
- Python Tutor code visualizer: Visualize code in Python, JavaScript, C, C++, and Java
- pathrise-python-tutor/embedding-HOWTO.md at master ยท pathrise-eng/pathrise-python-tutor
ๆง่ฝๅทฅๅ ท
ไบๅ็
ๅ็ซฏๅผๅ
็ฝ็ปๅบๅปบ
็ฝ็ปๅผๅ
้ณ่ง้ขๅค็
ๆธธๆไธๅพๅๅค็
ๅฎๅ จๅ่
ๅไธ่งๅฏ
็ไบงๅฎ่ทต
ไผ็งไบงๅ
awesome series
vinta/awesome-python
- vinta/awesome-python: A curated list of awesome Python frameworks, libraries, software and resources
- Awesome Python
ๅบ็กๅบ
ๅ ็ฝฎๅบไป็ป
osๅบ
็ฏๅขๅ้่ฎพ็ฝฎๅๅฆ็จ
ๆฌๆฅๆ็ฎๅจๆง่ก็ฌ่ซ่ๆฌๆถ้่ฟ็ฏๅขๅ้่ฎพ็ฝฎๅๆขๆฅๅๆๅจ็ป่ฟๆๅ็ญ้ช่ฏ็ ๆๆฎต๏ผไฝๆฏPythonๅชไผๅจ็ฌฌไธๆฌก่ฟ่กๆถๆ่ท็ฏๅขๅ้๏ผๆไปฅไธ็ฐๅฎใ
ไธไธช mapping ๅฏน่ฑก๏ผๅ ถไธญ้ฎๅผๆฏไปฃ่กจ่ฟ็จ็ฏๅข็ๅญ็ฌฆไธฒใ ไพๅฆ๏ผenviron['HOME'] ๆฏไฝ ็ไธป็ฎๅฝ๏ผๅจๆไบๅนณๅฐไธ๏ผ็่ทฏๅพๅ๏ผ็ธๅฝไบ C ไธญ็ getenv("HOME")ใ
่ฟไธชๆ ๅฐๆฏๅจ็ฌฌไธๆฌกๅฏผๅ ฅ os ๆจกๅๆถๆ่ท็๏ผ้ๅธธไฝไธบ Python ๅฏๅจๆถๅค็ site.py ็ไธ้จๅใ้คไบ้่ฟ็ดๆฅไฟฎๆน os.environ ไนๅค๏ผๅจๆญคไนๅๅฏน็ฏๅขๆๅ็ๆดๆนไธไผๅๆ ๅจ os.environ ไธญใ
่ฏฅๆ ๅฐ้คไบๅฏไปฅ็จไบๆฅ่ฏข็ฏๅขๅค๏ผ่ฟ่ฝ็จไบไฟฎๆน็ฏๅขใๅฝ่ฏฅๆ ๅฐ่ขซไฟฎๆนๆถ๏ผๅฐ่ชๅจ่ฐ็จ putenv()ใ
ๅจUnix็ณป็ปไธ๏ผ้ฎๅๅผไผไฝฟ็จ sys.getfilesystemencoding() ๅ 'surrogateescape' ็้่ฏฏๅค็ใๅฆๆไฝ ๆณไฝฟ็จๅ ถไป็็ผ็ ๏ผไฝฟ็จ environbใ
ๆณจ่งฃ ็ดๆฅ่ฐ็จ putenv() ๅนถไธไผๅฝฑๅ os.environ ๏ผๆไปฅๆจ่็ดๆฅไฟฎๆน os.environ ใ ๆณจ่งฃ ๅจๆไบๅนณๅฐไธ๏ผๅ ๆฌ FreeBSD ๅ macOS๏ผ่ฎพ็ฝฎ environ ๅฏ่ฝๅฏผ่ดๅ ๅญๆณๆผใ ่ฏทๅ้ putenv() ็็ณป็ปๆๆกฃใ
ๅ่่ตๆบ
ๆฅๅฟๅบไป็ป
ๅ่่ตๆบ
ๅผๅธธ่ฟฝ่ธชๅบ
ๅบ็กไพๅญ
import traceback
try:
do_something()
except Exception:
#traceback.print_exc(file=sys.stdout)
loggers.info(traceback.format_exc())