Code test environment: hadoop2.4
Application Scenario: this technique can be used to customize the output data format, including the display form, output path, and output file name of the output data.
Hadoop's built-in output file
About format formatting output and format formatting
What isFormat?
Compared with the basic formatting output, the "%" method is used. The format function is powerful. This function uses the string as a template and uses the input parameters for formatting, the braces "{}" a
The format () function is used to format the output string in Python. a string is a class and can be used as a method. Python is a fully object-oriented language and everything is an object; string parameters are represented by {NUM}, 0, indicating the first parameter, 1, indicating the second parameter, followed by increments; use quot;: quot ;, specifies the
Printf (), scanf ()
% C --------------- output a character
% D ----------------- output a signed decimal integer
% E (% E) ------------ output a real number of floating-point numbers in the form of normalized exponent. Only 6 digits are valid.
Number, which includes one integer and five decimal places. The exponent part is connected to three digits in total)
% F
The Python string is formatted using the "character% format 1% format 2 characters"% (variable 1, variable 2), and the% format represents the type of the accepted variable. Simple examples of use are as follows:
# Example: String formatting
Name = ' 17jo 'print ' www.%s.com '%name>> www.17jo.com
Name = ' 17jo 'Zone = ' com 'print ' www.%s.%s '% (name,zone)>> www
indicates the current time in the string format; % (levelname) s, for logger. debug, it is DEBUG, if it is logger. error, it is ERROR; % (message) s, if there is a logger. warning ("HAHA") is the string HAHA at the % (message) s position. The more detailed format is as follows:
% (Name) s
Logger name
% (Levelno) s
Log level in digital form
% (Levelname) s
Log level in t
detailed format characters are as follows:
% (name) s
Logger's name.
% (levelno) s
log level in digital form
% (levelname) s
The log level in text form
% (pathname) s
The full pathname of the module that called the log output function, may not have
% (filename) s
filename of the module t
Formatted input and output, is in the
If you modify the format of the input and output, will affect the subsequent format, you need to reset, generally in the format type before adding "No", you can;
Support, 8, 16, default 10, and uppercase (uppercase) mode;
Code:
* *
The format output string in Python uses the format () function, the string is the class, you can use the method;
Python is a fully object-oriented language, and everything is an object;
The parameters of the string are represented by {NUM}, 0, representing the first parameter, 1, representing the second parameter, and then sequentially sliding scale;
Use ":" To
/* Use ReadLine () to complete the input and output of the console */using system;namespace test{class test1{static void Main (string[] args) {Console.Write (" Please enter: ");//output Please enter and do not wrap string read = Console.ReadLine ();//Assign the input to variable readconsole.write (" You enter the content: ");//Console output The content you enter
1006. Output an integer in another format, and an integer in the 1006 format
1/* 2 * Main. c 3*1006. output an integer 4 * Created on: August 28, 2014 5 * Author: boomkeeper 6 ************ passed the test *********** 7 */8 9 # include
Question link:
Http://pat.zju.edu.cn/contests/pat-b-practise/1006
Write a program:
In Javaweb application, the date returned through the AJAX query is similar to the following "2010-08-01 18:22:00.0", how to according to the hope of the results show that often cost some trouble, here provide two methods to solve this problem, for reference only. The format method is not perfect, but it can satisfy most of the needs.
One, the effect chart
Second, the original code
1. Analytic method
/**
* Output
Python log format output and time format
formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s","%Y%b%d-%H:%M:%S")
The above % Y and so on are time formats, so to understand the above, Let's first look at the Python time format.
% A-abbreviated weekday name
% A-full weekday name
% B-abbreviated mo
Str. Format ("Formatting control string", output list);The format control string consists of a format string and a non-formatted string enclosed in double quotation marks. Where the non-format string is output as-is.A
This paper summarizes some simple and basic forms of output formatting and the basic usage form of the function Format function.String Formatting code:
format
Description
%%
Percent Sign
%c
Characters and their ASCII code
%s
String
%d
Signed integer (decim
output 64-bit integers. The MSVC platform is valid.%i64u,%I64d. Note Capitalize the last summary, a byte of%C,%HHU,%HHD, etc., two bytes with%hu,%hd, four bytes with%d,%u 8 bytes of%lld,%llu and so on. Try not to use%I64d is not compatible with this format. Adhering to the spirit of open source, the above content is welcome to correct, add!respect for the original, respect for intellectual property, starti
1. Text Format
// Create a new font
LOGFONT log; // struct variable
CFont font; // font object
// Set attributes
Log. lfCharSet = ANSI_CHARSET;
Log. lfClipPrecision = 23; // specifies the font cropping precision.
Log. lfEscapement = 0; // the tilt of the font relative to the X axis is 0.
Log. lfHeight = 50; // The font height is 50.
Strcpy (log. lfFaceName, "new font"); // font name
Log. lfItalic = 0; // 0 indicates non-italic
Log. lfOrientation = 900
Format a sentence-format the output sentence
//FormataSentence#include
Result:
Pleaseinputthesentenceandtheperiodisend:theANswertolife,theUniverse,andeverythingIS42.Theanswertolife,theuniverse,andeverythingis42
Format a sentence-format the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.