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.mzph.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,…