ip登錄打印機怎么打印_不要打印,登錄。

ip登錄打印機怎么打印

Often on Python, especially as a beginner, you might print( ) a variable in order to see what is happening in your program. It is possible if you rely on too many print statements throughout your program you will face the nightmare of having to comment them all out towards the end. A much more pythonic way to see what the program is doing is logging. You can then limit your prints to command line outputs that the end-user wants to see.

通常在Python上(尤其是作為初學者),您可以將變量print()以便查看程序中正在發生的事情。 如果您在整個程序中依賴過多的打印語句,則可能會面臨噩夢,不得不在最后將所有注釋都注釋掉。 查看程序正在執行的另一種Python方法是日志記錄。 然后,您可以將打印內容限制為最終用戶希望查看的命令行輸出。

為什么要登錄? (Why log?)

Logging is a comfortable tool to see the status of the program in the development phase. It is ideal if:

日志記錄是在開發階段查看程序狀態的便捷工具。 理想的情況是:

  1. You want to differentiate between debug output and program output

    您要區分調試輸出和程序輸出
  2. You don’t want irrelevant stdout in your final product

    您不想在最終產品中使用無關緊要的標準配置
  3. You would like to disable all stdout after development and test

    您想在開發和測試后禁用所有stdout
  4. You want to save your program execution history to a file with meta information like time and more detailed debug information.

    您想要將程序執行歷史記錄保存到包含元信息(例如時間和更詳細的調試信息)的文件中。

如何登錄? (How to log?)

You log in python using the logging module.

您可以使用日志記錄模塊登錄python。

import logging

The logging module provides some default states of logging various status messages in your program. The default levels are DEBUG, INFO, WARNING, ERROR, and CRITICAL.

日志記錄模塊提供了一些默認狀態,用于記錄程序中的各種狀態消息。 默認級別為DEBUGINFOWARNINGERRORCRITICAL

If you execute the following program:

如果執行以下程序:

import logging
import os
savepath = ‘path/to/save/at/’if not os.path.exists(savepath):
logging.warning(‘Warning! The savepath provided doesn\’t exist!'
'Saving at current directory ‘)
savepath = os.getcwd()
logging.info(‘savepath reset at %s’,str(savepath))else:
logging.info('Savepath provided is correct,'
'saving at %s’,str(savepath))

The path in the example Doesn't exist. You will see the following output:

示例中的路徑不存在。 您將看到以下輸出:

WARNING:root:warning! The savepath provided doesn’t exist!Saving at current directory

The new current save path information, that is logging.info is not displayed.

不顯示新的當前保存路徑信息,即logging.info。

This is because the default level of severity of output is “warning”. The order of severity is as follows:

這是因為默認的輸出嚴重性級別是“警告”。 嚴重性順序如下:

DEBUG

DEBUG

INFO

INFO

WARNING (This is default)

WARNING (這是默認設置)

ERROR

ERROR

CRITICAL

CRITICAL

If you want to see outputs of a lower severity level, you have to explicitly set them in the logging configuration. Start a new interpreter after this setting, else it won’t work.

如果要查看較低嚴重性級別的輸出,則必須在日志記錄配置中顯式設置它們。 進行此設置后,請啟動新的解釋器,否則將無法使用。

logging.basicConfig(level = logging.DEBUG)

Now, everything will be printed out, starting from level debug.

現在,從級別調試開始,所有內容都將被打印出來。

output:

輸出:

WARNING:root:warning! The savepath provided doesn’t exist! Saving at current directory INFO:root:savepath reset at path/to/current/directory

That is awesome! But for a decent log, we perhaps want to see more information and make it available in a separate file. This can be set using the format and filename in the configuration. Add the desired configuration at the beginning of your file:

太棒了! 但是對于一個像樣的日志,我們可能希望查看更多信息,并在單獨的文件中提供它。 可以使用配置中的格式和文件名進行設置。 在文件開頭添加所需的配置:

logging.basicConfig(filename=’logfilename.log’,level = 
logging.DEBUG,format=’%(asctime)s %
(message)s’,
datefmt=’%d/%m/%Y %I:%M:%S %p’)

This logs your information to logfilename.log along with timestamps.

這會將您的信息和時間戳一起記錄到logfilename.log中。

13/06/2020 05:14:47 PM warning! The savepath provided doesn’t exist!  
Saving at current directory
13/06/2020 05:14:47 PM savepath reset at current/working/directory

The next time you run the file, logs get appended to the textfile, so that you have a historic record of your logs in one place. You can also change this and create a new text file each time by adding this to your logging.basicConfig

下次運行該文件時,日志將追加到文本文件中,這樣一來,您就可以在歷史記錄中記錄日志。 您還可以通過將其添加到logging.basicConfig中來更改此設置并每次創建一個新的文本文件。

filemode='w'

You can disable all logging centrally by adding the following to your script, without having to comment each of the messages out:

您可以通過在腳本中添加以下內容來集中禁用所有日志記錄,而不必注釋掉每條消息:

logger = logging.getLogger()
logger.disabled = True

Alternatively, you can choose to change the level of output needed to be written to the log file to only enable warning and critical error messages to the end user.

或者,您可以選擇更改需要寫入日志文件的輸出級別,以僅向最終用戶啟用警告和嚴重錯誤消息。

That was a primer to logging on python. Logging offers much more flexibility than described above (Handlers, filters, changing the default log levels, etc) But this should be enough to start using basic logging and do away with print statements.

那是登錄python的入門。 日志記錄提供了比上述更多的靈活性(處理程序,過濾器,更改默認日志級別等),但這足以開始使用基本日志記錄并消除打印語句。

翻譯自: https://towardsdatascience.com/dont-print-log-85df4c153abb

ip登錄打印機怎么打印

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390558.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390558.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390558.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

leetcode 451. 根據字符出現頻率排序

給定一個字符串,請將字符串里的字符按照出現的頻率降序排列。 示例 1:輸入: "tree"輸出: "eert"解釋: e出現兩次,r和t都只出現一次。 因此e必須出現在r和t之前。此外,"eetr"也是一個有效的答案。 示例 2:輸入…

Spring-Security 自定義Filter完成驗證碼校驗

Spring-Security的功能主要是由一堆Filter構成過濾器鏈來實現,每個Filter都會完成自己的一部分工作。我今天要做的是對UsernamePasswordAuthenticationFilter進行擴展,新增一個Filter,完成對登錄頁面的校驗碼的驗證。下面先給一張過濾器的說明…

如何使用Ionic和Firebase在短短三天內創建冠狀病毒跟蹤器應用程序

I am really fond of Hybrid App technologies – they help us achieve so much in a single codebase. Using the Ionic Framework, I developed a cross-platform mobile solution for tracking Coronavirus cases in just 3 days. 我真的很喜歡Hybrid App技術-它們可以幫助…

二、Java面向對象(7)_封裝思想——this關鍵字

2018-04-30 this關鍵字 什么是this: 表示當前對象本身,或當前類的一個實例,通過 this 可以調用本對象的所有方法和屬性。 this主要存在于兩個地方: 1)構造函數:此時this表示調用當前創建的對象 2)成員方法中…

機器學習模型 非線性模型_調試機器學習模型的終極指南

機器學習模型 非線性模型You’ve divided your data into a training, development and test set, with the correct percentage of samples in each block, and you’ve also made sure that all of these blocks (specially development and test set) come from the same di…

leetcode 645. 錯誤的集合

集合 s 包含從 1 到 n 的整數。不幸的是,因為數據錯誤,導致集合里面某一個數字復制了成了集合里面的另外一個數字的值,導致集合 丟失了一個數字 并且 有一個數字重復 。 給定一個數組 nums 代表了集合 S 發生錯誤后的結果。 請你找出重復出…

Linux環境變量總結

現在每天測試到時候會與Linux打交道,自然也會用到環境變量了。看了網上幾篇文章,結合自己到實踐和看法,總結以下Linux的環境變量吧。一、什么是環境變量?環境變量相當于給系統或用戶應用程序設置的一些參數, 具體起什么作用這當然…

目錄指南中的Python列表文件-listdir VS system(“ ls”)通過示例進行解釋

🔹歡迎 (🔹 Welcome) If you want to learn how these functions work behind the scenes and how you can use their full power, then this article is for you.如果您想了解這些功能在后臺如何工作以及如何充分利用它們的功能,那么本文適合…

Java多線程并發學習-進階大綱

1、synchronized 的實現原理以及鎖優化?2、volatile 的實現原理?3、Java 的信號燈?4、synchronized 在靜態方法和普通方法的區別?5、怎么實現所有線程在等待某個事件的發生才會去執行?6、CAS?CAS 有什么缺陷…

大數據定律與中心極限定理_為什么中心極限定理對數據科學家很重要?

大數據定律與中心極限定理數據科學 (Data Science) The Central Limit Theorem is at the center of statistical inference what each data scientist/data analyst does every day.中心極限定理是每個數據科學家/數據分析師每天所做的統計推斷的中心。 Central Limit Theore…

useEffect語法講解

useEffect語法講解 用法 useEffect(effectFn, deps)能力 useEffect Hook 相當于 componentDidMount,componentDidUpdate 和 componentWillUnmount 這三個函數的組合。 可以模擬渲染后、更新后、銷毀三個動作。 案例演示 渲染后更新標題 useEffect(()>{doc…

leetcode 726. 原子的數量

給定一個化學式formula(作為字符串),返回每種原子的數量。 原子總是以一個大寫字母開始,接著跟隨0個或任意個小寫字母,表示原子的名字。 如果數量大于 1,原子后會跟著數字表示原子的數量。如果數量等于 1…

web相關基礎知識1

2017-12-13 09:47:11 關于HTML 1.絕對路徑和相對路徑 相對路徑:相對于文件自身為參考。 (工作中一般是使用相對路徑) 這里我們用html文件為參考。如果說html和圖片平級,那直接使用src 如果說圖片在和html平級的文件夾里面&#xf…

JavaScript循環:標簽語句,繼續語句和中斷語句說明

標簽聲明 (Label Statement) The Label Statement is used with the break and continue statements and serves to identify the statement to which the break and continue statements apply. Label語句與break和continue語句一起使用,用于標識break和continue語…

馬約拉納費米子:推動量子計算的“天使粒子”

據《人民日報》報道,以華人科學家為主體的科研團隊找到了正反同體的“天使粒子”——馬約拉納費米子,從而結束了國際物理學界對這一神秘粒子長達80年的漫長追尋。該成果由加利福尼亞大學洛杉磯分校何慶林、王康隆課題組,美國斯坦福大學教授張…

leetcode 1711. 大餐計數

大餐 是指 恰好包含兩道不同餐品 的一餐,其美味程度之和等于 2 的冪。 你可以搭配 任意 兩道餐品做一頓大餐。 給你一個整數數組 deliciousness ,其中 deliciousness[i] 是第 i?????????????? 道餐品的美味程度,返回你可以用…

您的第一個簡單的機器學習項目

This article is for those dummies like me, who’ve never tried to know what machine learning was or have left it halfway for the sole reason of being overwhelmed. Follow through every line and stay along. I promise you’d be quite acquainted with giving yo…

eclipse報Access restriction: The type 'BASE64Decoder' is not API處理方法

今天從svn更新代碼之后,由于代碼中使用了BASE64Encoder 更新之后報如下錯誤: Access restriction: The type ‘BASE64Decoder’ is not API (restriction on required library ‘D:\java\jdk1.7.0_45\jre\lib\rt.jar’) 解決其實很簡單,把JR…

【躍遷之路】【451天】程序員高效學習方法論探索系列(實驗階段208-2018.05.02)...

(躍遷之路)專欄 實驗說明 從2017.10.6起,開啟這個系列,目標只有一個:探索新的學習方法,實現躍遷式成長實驗期2年(2017.10.06 - 2019.10.06)我將以自己為實驗對象。我將開源我的學習方法,方法不斷…

react jest測試_如何使用React測試庫和Jest開始測試React應用

react jest測試Testing is often seen as a tedious process. Its extra code you have to write, and in some cases, to be honest, its not needed. But every developer should know at least the basics of testing. It increases confidence in the products they build,…