1.背景
看到这里提到了pprint。
打算去试试.
2.pprint简介
找到在线官网解释:
pprint — Data pretty printer
就是一个,方便大家打印一些,相对复杂的变量的好东西。
3.使用pprint
去写点代码试试。
代码:
代码如下:
#-------------------------------------------------------------------------------
# Name: 【记录】折腾Python中的pprint
# Author: Crifan Li
#
# Created: 06/01/2013
# Copyright: (c) Crifan Li 2013
#-------------------------------------------------------------------------------
import pprint;
import re;
def pprintDemo():
varsList = [
[1, 2, 3],
["ab", "c", "def"],
re.compile("\w+"),
("123", "abc"),
{
"key1":"value1",
"key2":"value2",
},
];
for value in varsList:
print value;
print "-"*80;
pp = pprint.PrettyPrinter(indent=4);
for value in varsList:
pp.pprint(value);
print "="*80;
stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'];
stuff.insert(0, stuff[:]);
print stuff;
print "-"*80;
pp.pprint(stuff)
if __name__ == '__main__':
pprintDemo();
效果:
代码如下:
[1, 2, 3]
['ab', 'c', 'def']
<_sre.sre_pattern object at>
('123', 'abc')
{'key2': 'value2', 'key1': 'value1'}
--------------------------------------------------------------------------------
[1, 2, 3]
['ab', 'c', 'def']
<_sre.sre_pattern object at>
('123', 'abc')
{ 'key1': 'value1', 'key2': 'value2'}
================================================================================
[['spam', 'eggs', 'lumberjack', 'knights', 'ni'], 'spam', 'eggs', 'lumberjack', 'knights', 'ni']
--------------------------------------------------------------------------------
[ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'],
'spam',
'eggs',
'lumberjack',
'knights',
'ni']
4.总结
pprint,有点意思。
以后可以用在代码调试过程中。

Pythonusesahybridmodelofcompilationandinterpretation:1)ThePythoninterpretercompilessourcecodeintoplatform-independentbytecode.2)ThePythonVirtualMachine(PVM)thenexecutesthisbytecode,balancingeaseofusewithperformance.

Pythonisbothinterpretedandcompiled.1)It'scompiledtobytecodeforportabilityacrossplatforms.2)Thebytecodeistheninterpreted,allowingfordynamictypingandrapiddevelopment,thoughitmaybeslowerthanfullycompiledlanguages.

Forloopsareidealwhenyouknowthenumberofiterationsinadvance,whilewhileloopsarebetterforsituationswhereyouneedtoloopuntilaconditionismet.Forloopsaremoreefficientandreadable,suitableforiteratingoversequences,whereaswhileloopsoffermorecontrolandareusefulf

Forloopsareusedwhenthenumberofiterationsisknowninadvance,whilewhileloopsareusedwhentheiterationsdependonacondition.1)Forloopsareidealforiteratingoversequenceslikelistsorarrays.2)Whileloopsaresuitableforscenarioswheretheloopcontinuesuntilaspecificcond

Pythonisnotpurelyinterpreted;itusesahybridapproachofbytecodecompilationandruntimeinterpretation.1)Pythoncompilessourcecodeintobytecode,whichisthenexecutedbythePythonVirtualMachine(PVM).2)Thisprocessallowsforrapiddevelopmentbutcanimpactperformance,req

ToconcatenatelistsinPythonwiththesameelements,use:1)the operatortokeepduplicates,2)asettoremoveduplicates,or3)listcomprehensionforcontroloverduplicates,eachmethodhasdifferentperformanceandorderimplications.

Pythonisaninterpretedlanguage,offeringeaseofuseandflexibilitybutfacingperformancelimitationsincriticalapplications.1)InterpretedlanguageslikePythonexecuteline-by-line,allowingimmediatefeedbackandrapidprototyping.2)CompiledlanguageslikeC/C transformt

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools
