国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python中使用sys模板和logging模塊獲取行號和函數名的方法

2020-02-23 05:18:41
字體:
來源:轉載
供稿:網友

對于python,這幾天一直有兩個問題在困擾我:
1.python中沒辦法直接取得當前的行號和函數名。這是有人在論壇里提出的問題,底下一群人只是在猜測python為什么不像__file__一樣提供__line__和__func__,但是卻最終也沒有找到解決方案。
2.如果一個函數在不知道自己名字的情況下,怎么才能遞歸調用自己。這是我一個同事問我的,其實也是獲取函數名,但是當時也是回答不出來。


但是今晚!所有的問題都有了答案。
一切還要從我用python的logging模塊說起,logging中的format中是有如下選項的:

代碼如下:
%(name)s            Name of the logger (logging channel)
%(levelno)s         Numeric logging level for the message (DEBUG, INFO,
                    WARNING, ERROR, CRITICAL)
%(levelname)s       Text logging level for the message ("DEBUG", "INFO",
                    "WARNING", "ERROR", "CRITICAL")
%(pathname)s        Full pathname of the source file where the logging
                    call was issued (if available)
%(filename)s        Filename portion of pathname
%(module)s          Module (name portion of filename)
%(lineno)d          Source line number where the logging call was issued
                    (if available)
%(funcName)s        Function name
%(created)f         Time when the LogRecord was created (time.time()
                    return value)
%(asctime)s         Textual time when the LogRecord was created
%(msecs)d           Millisecond portion of the creation time
%(relativeCreated)d Time in milliseconds when the LogRecord was created,
                    relative to the time the logging module was loaded
                    (typically at application startup time)
%(thread)d          Thread ID (if available)
%(threadName)s      Thread name (if available)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长顺县| 蒲江县| 中山市| 永泰县| 谷城县| 陵川县| 崇阳县| 永登县| 蓬莱市| 安国市| 江阴市| 临高县| 凭祥市| 通城县| 平乡县| 永平县| 赤壁市| 治县。| 沧州市| 南木林县| 雅安市| 安阳县| 临西县| 扎兰屯市| 双城市| 明溪县| 高州市| 平泉县| 滁州市| 禹城市| 白朗县| 嘉峪关市| 同仁县| 富顺县| 屯留县| 黑龙江省| 建水县| 调兵山市| 伊宁市| 霍林郭勒市| 南木林县|