Note the problem caused by an excessively long line in the Python source file. First of all, this problem is not my problem, it is a post I saw when I was grinding Python, the address of the post is here, if you are interested, the cause is that the post owner defined a super long set in the source file, the set is as follows

e = {'Co-op'.'economic'.'and'.'bill'.'Travel Agency'.'maintenance'.'escort'.'Management Consulting'.'built to'.'health'.'sculpture'.'Shanghai Police'.'jewelry'.'business'.'computer'.Talent Network.'vegetarian'.'Household goods'.'Aluminium products'.'department'.'Banks'.'Industrial Park'.'Business School'.'Driving Training'.'life'.'Diving Service'.TV station.'trade'.'side'.'aluminium'.'venture capital'.'business'.'Police Association'.'test'.'show'.'financial'.'ceramics'.'Business Department'.'glasses'.'property'.'and'.'the'.'preschool education'.'supermarket'.'Plant Protection Machine User'.'farmers take'.'education'.'exhibition'.'sales'.'fruit'.'insurance'.'Ecological Park'.'Business Management'.'print'.'Electricity Board'.'spread'.'credit'.'demolition'.'decoration'.'pension'.'life'.'Living Hall'.'financial'.'food'.'Advisory Services'.' ' '.'the individual'.'the office'.'Freelance'.'anime'.'the'.'business'.'Old people'.'agricultural materials'.Xinhua News Agency.'Fair'.Xinhua Net.'jewelry'.'show'.'trade'.'patent'.'the city'.'experience'.'Internet cafe'.'Water sensitive paper test spray 潵 effect'.'bankruptcy'.Dashen Net.'Promotion Society'.'wine'.'tobacco'.'domestic'.'Wei Marine Police'.'Tap water'.'agents'.'sales'.'creative'.'fund'.'Import and export'.'finance'.'unionpay'.'clothing'.'暂无'.'adults'.'film'.'VC'.'heroes'."Feng shui".'marketing'.'photography'.'Small Business'.'advertising'.'international'.'dress'.'recruitment'.'entrepreneurship'.'news'.'veterinary drugs'.'Sports Day'.'mother'.'Not decided.'.'Rural Credit Cooperatives'.'human'.'International freight'.'Vocational Skills'.'Intellectual Property'.'hotel'.'hair cut'.'ZhongCai'.'business'.'medical'.'securities'.'hotel'.'trade'.'distribution'.'personal'.'the newspaper'.'The Age of The Universe'.'travel'.'show'.'show'.'Yuchen Net'.'Publishing house'.'the media'.'Certification Consulting'.'E-commerce'.'incubation'.'make up'.'Vocational college'.'auction'.'buried'.'general'.'hardware'.'the media'.'Accessory Shop'.'Application Services'.'mother'.'assistant'.Xinhua Bookstore.'卫视'.'road shop'.'Driver Training'.'props'.'the strong'.'Snack bar'.'unemployed'.'hospital'.'Foreign trade resale'.'training'.'the club'.'fun'.'clinic'.'Asset Management'.'Daily necessities'.'... '.The 'capital'.'manners'.'business'.'Power Supply Board'.'Administration'.'culture'.'users'.'association'.'the government'.'business'.'Exhibition'.'Self-employed'.'food'.'primary'.'Cloud Knows sound'.'Subway Shop'.Credit Union.'CCTV'.'garden'.'grave'.'school'.'magazine'.'Blockchain'.'store'.'Club'.'wealth'.'food'.'stake'.'Convenience store'.'investment'.'organs'.'rent'.'tea'.'the farmer'.'seed industry'.'Vocational and technical College'.The 'chain'.'politics'.'metal'.'electricity'.'political'.'Suffice Ind. Tech. Ltd.'.'packaging'.'kennel'.'the watch'.'fibers'.'New Media'.'Exchange center'.'trade'.'branch'.'paper'.'#NAME? '.'Quality Inspection'.'community'.'information'.'services'.'guarantee'}

print(e)
Copy the code

Then run the source file directly and get the following error:

python test.py 

  File "test.py", line 3
SyntaxError: Non-UTF- 8 - code starting with '\xe7' in file test.py on line 3, but no encoding declared; see http://python.org/dev/peps/pep- 0263./ for details
Copy the code

Then I tried adding Shebang # -* -coding: utf8 -*- that declared the source code to work.

Now that’s interesting. Why is that? Holding there is no big god’s reply to continue to turn down, as expected, thigh appeared.

Looking at the source code for Python3.6.6, I think Python has a problem parsing the source code, and the code involved is in decoding_fgets.

Decoding_fgets reads a line of source code into buffer when Python parses it. Decoding_fgets may read the source code from a file in one of two ways:

1. If the file code is specified at the beginning of the file or the file contains UTF-8 BOM, use IO. Open to open the file with that code and use readline to read a line of source code.

2. If no encoding is specified, use Py_UniversalNewlineFgets to read a line of source code.

Use method 1 to read the source code without any problems. When using valid_utf8, Python checks for valid UTF8 encoding. This is usually fine, but the initial buffer size is 1024 bytes. If a line of code is too long (over 1023 bytes), multiple reads are required. The buffer length increases by 1024 each time. If you’re unlucky enough to slice the bytes of a character, this can lead to a coding error.

Then I follow the thigh idea to the code Format, as expected feasible…

e = {'Co-op'.'economic'.'and'.'bill'.'Travel Agency'.'maintenance'.'escort'.'Management Consulting'.'built to'.'health'.'sculpture'.'Shanghai Police'.'jewelry'.'business'.'computer'.Talent Network.'vegetarian'.'Household goods'.'Aluminium products'.'department'.'Banks'.'Industrial Park'.'Business School'.'Driving Training'.'life'.'Diving Service'.TV station.'trade'.'side'.'aluminium'.'venture capital'.'business'.'Police Association'.'test'.'show'.'financial'.'ceramics'.'Business Department'.'glasses'.'property'.'and'.'the'.'preschool education'.'supermarket'.'Plant Protection Machine User'.'farmers take'.'education'.'exhibition'.'sales'.'fruit'.'insurance'.'Ecological Park'.'Business Management'.'print'.'Electricity Board'.'spread'.'credit'.'demolition'.'decoration'.'pension'.'life'.'Living Hall'.'financial'.'food'.'Advisory Services'.' ' '.'the individual'.'the office'.'Freelance'.'anime'.'the'.'business'.'Old people'.'agricultural materials'.Xinhua News Agency.'Fair'.Xinhua Net.'jewelry'.'show'.'trade'.'patent'.'the city'.'experience'.'Internet cafe'.'Water sensitive paper test spray 潵 effect'.'bankruptcy'.Dashen Net.'Promotion Society'.'wine'.'tobacco'.'domestic'.'Wei Marine Police'.'Tap water'.'agents'.'sales'.'creative'.'fund'.'Import and export'.'finance'.'unionpay'.'clothing'.'暂无'.'adults'.'film'.'VC'.'heroes'."Feng shui".'marketing'.'photography'.'Small Business'.'advertising'.'international'.'dress'.'recruitment'.'entrepreneurship'.'news'.'veterinary drugs'.'Sports Day'.'mother'.'Not decided.'.'Rural Credit Cooperatives'.'human'.'International freight'.'Vocational Skills'.'Intellectual Property'.'hotel'.'hair cut'.'ZhongCai'.'business'.'medical'.'securities'.'hotel'.'trade'.'distribution'.'personal'.'the newspaper'.'The Age of The Universe'.'travel'.'show'.'show'.'Yuchen Net'.'Publishing house'.'the media'.'Certification Consulting'.'E-commerce'.'incubation'.'make up'.'Vocational college'.'auction'.'buried'.'general'.'hardware'.'the media'.'Accessory Shop'.'Application Services'.'mother'.'assistant'.Xinhua Bookstore.'卫视'.'road shop'.'Driver Training'.'props'.'the strong'.'Snack bar'.'unemployed'.'hospital'.'Foreign trade resale'.'training'.'the club'.'fun'.'clinic'.'Asset Management'.'Daily necessities'.'... '.The 'capital'.'manners'.'business'.'Power Supply Board'.'Administration'.'culture'.'users'.'association'.'the government'.'business'.'Exhibition'.'Self-employed'.'food'.'primary'.'Cloud Knows sound'.'Subway Shop'.Credit Union.'CCTV'.'garden'.'grave'.'school'.'magazine'.'Blockchain'.'store'.'Club'.'wealth'.'food'.'stake'.'Convenience store'.'investment'.'organs'.'rent'.'tea'.'the farmer'.'seed industry'.'Vocational and technical College'.The 'chain'.'politics'.'metal'.'electricity'.'political'.'Suffice Ind. Tech. Ltd.'.'packaging'.'kennel'.'the watch'.'fibers'.'New Media'.'Exchange center'.'trade'.'branch'.'paper'.'#NAME? '.'Quality Inspection'.'community'.'information'.'services'.'guarantee'}

print(e)
Copy the code

Shebang with or without declaring the source code will not return an error

Of course, if the PEP8 specification honestly writes the Shebang that declares the source code (even Python3 should), the PEP8 specification’s maximum length does not cause this problem. However, in terms of the Python interpreter reading from source files, it’s really a bit of a jump, as CPython reads from source files.