Python Learning Knowledge Base

Source: Internet
Author: User
Tags readline knowledge base

>>> with open ("Login.txt", "r+", ending= "Utf-8") as F:

... f.readline ()

File "<stdin>", Line 2 f.readline () ^ indentationerror:expected an indented block

Cause: No indentation, add a space or tab to a new line

With open ("Users_info", "RW", encoding= "Utf-8") as F:for line in F:

If "Lisi" in line:

F.seek (F.tell ()-len (line))

Line= "Test 123 0"

F.write (line)

Oserror:telling position disabled by next () call

Why: Tell () cannot be used in a loop, the specific reason needs to be studied in depth

Typeerror:eval () Arg 1 must be a string, bytes or code object

Reason: Use the eval () method on a type that is not a Str,bytes,code object, such as I set a = {"Zhangsan" in Terminal, "123"},eval (a), which is the eval () method for the dictionary, the correct way is a= ' {" Zhangsan "," 123 "} ', Eval (a)

Python module and import appear importerror:no module named ' xxx ' problem

Reason: According to my experience in Java, the import error is because the code is placed under the direction (package), so the import is to add the prefix

For example: If the test.py file is established under module M1, import should be imported M1.test

PEP8 Code Style Error

Expected 2 blank lines, found 0 need two lines blank, 0 rows found

Cause: The file code should be empty two lines behind the comment

Typo:in Word incorrectly spelled

Cause: Word spelling error

variables, values, operators should be preceded by a space, comma should be followed by a space, the output string should be used such as "test%s", the% name, before and after the space

Python Learning Knowledge Base

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.