This article describes a way to print out a user's information in a Python dictionary
#log File Contents
Alex#123#1eric#123#1tony#123#1
# index.py Main program logic
# {' Tony ': [[' 123 ', ' 1 '], ' Alex ': [[' 123 ', ' 1 ']], ' Eric ': [[' 123 ', ' 1 ']} This is the result, please use Python to implement obj = open (' Log ', ' r ') line = Obj.readlines ()
The implementation code is as follows:#!/usr/bin/python#*-*coding:utf8*-*importosimportsysimporthashlibdefmd5sum (data): withopen (data, "RB") asf: NBSP;NBSP;MD5NBSP;=NBSP;HASHLIB.MD5 () foriin f.read (4096):ifi: md5.update (i) else: break md5=md5.hexdigest () returnmd5 "" " Finds the specified key in the specified dictionary, appends the value to value corresponding to the key if it exists, and saves a new element as a list if it does not exist, and
This use case is tested in python3.3.5 by:Input : input in Python is using input, the following example code means the input value is stored in the variable s, and the input sHere's a reminder: The value you get with input is a string type output: There are two ways to output s, the first way is to enter s in the screen directly, and then enter (). The second output is the use of print (s)format: using F
BackgroundRequirement: Print Word fileModule: Python-docxProblemPass the Xxx.doc file to the Python script, after execution, the console has no content outputAfter the inquiry learned that the general reason: Doc is an earlier generation of Word files, closed format, office or WPS is the use of anti-decoding to parse out, but also does not guarantee the perfect r
1 naming conventions for variable names:Consists of numbers, letters, and underscores, but you cannot name a variable with a number. For example A, B, C, name, User1 user_id, and so on can be used as variable names.1A,2B 3CD and so on are not. Special Note that you cannot use keywords in python syntax as variable names. Common "Class" "and" "as" "Insert" "while" "Elif" "Else" "Del" and so on.Variables in Python
Python exercise 008: print all prime numbers between 101-200, python101-200
[Python exercise question 008]Determine the number of prime numbers between-and output all prime numbers.
---------------------------------------------------------------------
This is a separate question. It is said that there are many solutions. My idea is: first create an integer lis
Use notepad ++ to learn python crawlers and print Chinese garbled characters on webpages,
Today, when I learned how to use python crawlers, I found that the Chinese characters on the crawled web pages are garbled. I searched for a solution on the Internet one by one and tried it one by one. Then I started to test it using other methods, it is normal to use the e
Purpose: When using Python, change the output color and style in the terminal.Environment: Ubuntu 16.4 python 3.5.2Scenario: When writing a small script, if we do not need to output to a file, perhaps just want to display information in the terminal, you can try to change the output text color and style, highlighting or just want to show.Looked up a little information:The character color of terminal is cont
Yang Hui Triangle, is a geometric arrangement of two-term coefficients in triangles
Each number equals two of the sum above it.
Each line of numbers is symmetrical, starting from 1 to become larger.
The number of the nth row has n items.
The nth row number and 2n-1.
The number of m in the nth row can be expressed as C (n-1,m-1), which is the number of combinations of m-1 elements taken from n-1 different elements.
The number of the nth row is equal to the number of
Before encountering this problem, try to compare several different results and summarize the difference between return and print.Summarize:One of the functions of return is returning the calculated valuePrint works by outputting data to the control sideNothing is output in the first result;In the fourth result, print Peven(n) whose return value is None.As a result, print prints the results to the console,
Print () function:The default carriage return when passing in a single parameter, the keyword end can be used to avoid the output after the carriage return ( newline ), or to end the output with a different string.>>> A, b = 0, 1>>> while B When multiple parameters are passed in, the output is separated by a space between multiple parameters. >>> i = 256*256>>> print (' The value of I ', I) the value of I i
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M00/9C/5C/wKioL1lvTniQoNmLAADo7qHXZ2k595.png-wh_500x0-wm_ 3-wmp_4-s_938396800.png "title=" Untitled. png "alt=" wkiol1lvtniqonmlaado7qhxz2k595.png-wh_50 "/>What to do if there is a prompt statement in front of the output result18.1Decimal Value Output650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M01/9C/5C/wKioL1lvTpeBbV4ZAAHS6XT1VE0983.png-wh_500x0-wm_ 3-wmp_4-s_1126558383.png "title=" Untitled. png "alt=" wkiol1lvtpebbv4zaahs6xt1
Rf+sublime Framework Test Interface:Python initially encountered an output return value problem, cannot be hit;def getbaseinfo (self, recordrelatednumber):Ret=self.comlib.getbaseinfo (Recordrelatednumber)return ret#直接返回数据ret, Problem solving# if Ret==0:# return 0# Else:# Return to self. GetLastError ()Direct return, problem, errorFormat problems; Unicodeencodeerror: ' ASCII ' codec can ' t encode character U ' \u7537 ' in position 119:ordinal not in range (128)After the file is introduced,Import
I think my algorithms are simpler and easier to understand than those on the web. As for the complexity of time, there is no comparison.Algorithm idea: Traversing the matrix from the outermost to the inner layer# My algorithmImport Mathdef Print_matrix (matrix): rec = [] # Store traversal element rows = Len (Matrix) cols = Len (matrix[0]) if rows L T cols: k = Math.ceil (ROWS/2) else: k = Math.ceil (COLS/2) for N in range (k): # Total number of loops # the
Today learning to use Python crawler when found to crawl the page Chinese will be garbled, has been online search solutions, a test past, found or garbled, and then I began to use other methods of testing, with Python's own editor Open is normal, found to be notepad++ The problem with this editor, I changed the encoding method for utf-8 without BOM, tried all settings, no use, new, open file default is always ANSI format, PYNPP this quick open. py For
This example describes how Python uses Reportlab to print all text files in a directory to PDF. Share to everyone for your reference. The implementation method is as follows:
#-*-Coding:utf8-*-#~ #----------------------------------------------------------------------Import Wlab #pip Install Wlab import reportlab.pdfbase.ttfonts #reportlab. Pdfbase.pdfmetrics.registerFont ( Reportlab.pdfbase.ttfonts.TTFont
#!/usr/bin/python#-*-Coding:utf-8-*-__author__ = ' Zuoanvip '#一般情况下我们要验证打开的页面是否正确, can be verified by the title and Current_url of the Web pageFrom selenium import WebdriverDriver = Webdriver. Firefox ()Driver.get (' http://www.baidu.com ')#获取当前的网页标题Driver.title#获取当前的页面URLDriver.current_url#设置等待时间, there are three ways: sleep () fixed wait time, implicitly_wait () Smart wait, over time to throw an exception, webdriverwait () in the set time interval o
About the python2.x and 3.x to bring the print does not wrap the problem: Yesterday had a push text, using the end = definition, to solve the small horizontal problem, but because of the screen display problem, if the string length is too large, it will cause inconvenience. Two or more print to split the case, how to maintain the horizontal output, the general is at the end of 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.