Tag Archives: Python

Python–TabError: inconsistent use of tabs and spaces in indentation

Detailed map traversal, teach you to master the complex gremlin query debugging method>>>

Python — error taberror: inconsistent use of tabs and spaces in indentation

blog description

The information involved in this article comes from Internet collation and personal summary, which means personal learning and experience summary. If there is any infringement, please contact me to delete it. Thank you

description

When running the flash framework, an error is reported. I can’t see whether it’s alive or dead. I see the information that it’s caused by the mixed use of the tab key and four space keys. Only one can solve this problem

thinking

The reason for this problem is that I edited the Python code on the Internet, and then I couldn’t see it in the online editor. I found the error for a long time, which was literally meaning. I selected all the code into pychar, and found that the code format was in disorder. I used the shortcut key to sort out the code Alt + Command + L, and the problem was solved

thank you

Omnipotent network

And industrious self

Python solves the problem of modulenotfounderror: no module named ‘queue’

Detailed map traversal, teach you to master the complex gremlin query debugging method>>>

Python solves the problem of modulenotfoundererror: no module named ‘queue’

Reference article:

(1) Python solves the problem of modulenotfounderror: no module named ‘queue’

(2) https://www.cnblogs.com/Sweettesting/p/11137965.html

Let’s make a note.

Problem solving: start Python and report “importerror: no module named site” error

“358141;”36941;”213822225945;” 20320;”25484;” 25569;”22797;” 26434;”Gremlin”35810;”35843;” 357973;”>>>

38382;- 39064;
32622;- Python-24452; 20294;- 21551;- Python-24635;-25253Imports; rror:Nomodulenamedsite “38169;” 35823;

[ root@tZgame ]’35;echo$PATH
/usr/local/sbin:/usr/local/bin:/usr/bin:/root/bin:/usr/lib/python2.7:/usr/lib/python2.7:/usr/lib/python2.7/site-packages:/usr/bin/python:/usr/lib64/python2.7
[ root@tZgame ]’35; echo$PYTHONHOME
/usr/bin/
[ root@tZgame ]’35; echo$PYTHONPATH
/usr/bin/
[ root@tZgame ]’35; whereispython
python:/usr/bin/python/usr/bin/python2.7/usr/lib/python2.7/usr/lib64/python2.7/usr/include/python2.7/usr/share/man/man1/python.1.gz
[ root@tZgame ]’35; whichpython
/usr/bin/python

\35;————- 38382;- 39064;- 28857;———–
[br] root@tZgame ]’35; python
Imports rror:Nomodulenamedsite

\35;———- 30475;- 38382;- 39064;- 28857;- 30456;——-
[Translated with Google Translate] root@tZgame ]’35; find/-namesite.py
/usr/lib64/python2.7/site.py

*35;——— 24403;- 38169;- 35823;- 209173;- v261744;——
[br] root@tZ You’re going to be going to be going to be going to be installiinstalliinstalliinstalliinstalliinstallithe hook<
importimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliinstalliimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimportimport \; sys.path<<<
> <.sys. sys. sys. sys. your.path<.path<<<

> ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————–python2.7/site.py
import site 35; precompiledfrom/usr/lib/python2.7/site.pyc ‘352;—————-24046;- 22788;
’35;/ usr/lib/python2.7/os.pycmatches/usr/lib/python2.7/os.py
importos’35;precompiledfrom/usr/lib/python2.7/os.pyc
importerrno’35;builtin
importposix’35; builtin

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$1919191919191919

209150;br>

PYTHONHOME PYTHONPATH <25193;<20805;- Python27169;- 2235922d;

37324;”23548;” site27169;”22359;” 38169;”24212;” 35813;”PYTHONPATH22686;” site27169;”223592nd;”

Site root@tZ And then you can find the/-name site.py*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

root@tZ You’re going to have to installinstallinstallinstallinstallinstallimport hook<<
import import import import import ; builtin<<
\\; installed installinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallinstallr/lib64/python2.7/os.pyc matches /usr/lib64/python2.7/os.py

30452;- 25509;- 21551;- Python-35797;- 357971;br> [br] root@tZ etc]’35; python
Python 2.7.5 (default, Jun 17 2014, 18:11:42)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.>>

35777;”3838382;” 39064;”20915;” p>

Object() takes no parameters of Python errors

Detailed map traversal, teach you to master the complex gremlin query debugging method>>>

'''
Createdon2016��4��26��
@author:zf
'''
classHello:
#���췽��_init_
def_init_(self,name):
self.name=name
defsayHello(self):
print("Hello{0}".format(self.name))

h=Hello("Python")
h.sayHello()

There was an error in object() takes no parameters when running. I didn’t find it at first, then I found it__ init__ ( CTRL +/verify is double dash, I only use one dash)

Reference blog: http://blog.csdn.net/liyajuan521/article/details/44409877

Python: How to Solve raise JSONDecodeError(“Expecting value”, s, err.value) from None json.decoder…

When dealing with the local JSON file, because of the change of the JSON format, the code can not run and the error occurs. Here are the solutions:

[initial code]

with open(path,'r') as f:
    a = json.loads(f.read())
    print(a)
    print(type(a))

[prompt error]

Traceback (most recent call last):
  File "C:\Users\14062\Desktop\json02.py", line 25, in <module>
    c = json.loads(b)
  File "C:\Users\14062\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\14062\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\14062\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

[solution]

with open(path,encoding='utf-8-sig', errors='ignore') as f:
     data = json.load(f, strict=False)
     print(data)

Python calculator error: can’t multiply sequence by non-int of type ‘float’

Example:

num1=input('input the first num: ')

num2=input('input the second num: ')
num3=num1*num2
print(num3)

After execution, the result is: input the first num: at this time, enter the integer on the keyboard and press enter

Input the second num: enter the integer again and press enter

Can’t multiply sequence by non int of type ‘float’

Reason: the input() function inputs a string format, so the integer you enter on the keyboard is not a positive integer, but a string format. Therefore, when executing the statement Num3 = num * num, an error will be reported. Because num1 and num2 are both strings, they cannot be multiplied

Solution: convert num1 and num2 into integers

Specific solutions

1. The third line of the code is changed to: Num3 = int (num1) * int (num2)

2. Change the first and second lines to: num1 = int (input (‘input the first num: ‘)

num2=int(input(‘input the first num: ‘))

Solution of syntax error: invalid character in identifier when writing Python code

Solution of syntax error: invalid character in identifier when writing Python code

   this error is usually caused by illegal spaces. Some advanced editors will directly display red wavy lines to prompt for errors. However, it will not prompt in environments like jupyter notebook, so this error is caused by illegal spaces

Solution:

   delete the original space , and then use tab to regenerate the space

Development:

   other similar errors using Jupiter notebook, such as: indentation error: undintent does not match any outer indentation level, are also caused by illegal spaces in indentation

   generally, if you write code directly, this problem will not appear. The reason for the above error is that you directly copy some code from PDF document, word document or web page to python. So the fundamental way to solve this problem is to write every line of code by yourself, so this problem will not occur

The solution of Python extension problem “unable to find vcvarsall. Bat”

When using C to write extensions to python3, we encountered the following problems:

Write * module. C and setup. Py files and execute them

python setup.py build

Unable to find vcfarsall.bat

I have VS2005 and VC6 on my machine, but I still report an error

Search a lot of information:

Online solutions are as follows:

Download MinGW environment and add environment variables

Use

python setup.py build –compiler=mingw32

I feel that this method just bypasses this problem, but it is not really a solution. Moreover, in my system, Python is compiled with VS, but the extension module is compiled with MinGW GCC. I feel that there may be a problem

But there is no detailed explanation on the Internet

After carefully reading the. Py file in the C/Python 32/lib/distutils directory, it is found that the sentence “unable to find vcvar sall. Bat” is in msvc9compiler. Py

Further study of this document reveals the problem

It looks for the vs directory in the registry, and then looks for vcvarsall.bat in the vs directory

But the problem is that in python32, the default is vc9.0, which is VS2008, so it can’t find the key value in the registry and returns none

productdir = Reg.get_ value(r”%s/Setup/VC” % vsbase,

“productdir”)

The value of vsbase is: software/Microsoft/Visual Studio/9.0

The specific modification code is as follows:

In msvc9compiler.py

def find_ Vcvarsall (version) is used to find vcvarsall. Bat version, which is the version number, is actually 9.0

vc_ env = query_ vcvarsall(VERSION, plat_ spec)

VERSION = get_ build_ Version () because python32 itself is built by vc9.0, version is 9.0

Modify the msvccompiler function:

vc_env = query_vcvarsall(VERSION, plat_spec)

For:

vc_env = query_vcvarsall(8.0, plat_spec)

But there is another sentence:

if VERSION < 8.0:
 
raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION)

It seems that distutils in Python 3.2 only supports compilers above VC8.0, that is, compilers above VS2005

A python namespace conflict, about the from import mechanism

 

from os import *
#import os

def foo():
    a = listdir("trainingDigits")
    b = open("trainingDigits/0_0.txt")

This code, if only enabled

from os import *

It will then be in

b = open(“trainingDigits/0_0.txt”)

This location reports

TypeError: Required argument ‘flags’ (pos 2) not found

If you enable only

import os

Name error: name ‘listdir’ is not defined will be reported at a = listdir (“training digits”)

The solution is

import os

def foo():
    a = os.listdir("trainingDigits")
    b = open("trainingDigits/0_0.txt")

Python Send Email Error: smtplib.SMTPException: SMTP AUTH extension not supported by server

Python sends e-mail. The 126 e-mail box used before is normal, but today it is changed to Hotmail, and this error has been reported all the time

smtplib.SMTPE xception:SMTPAUTHextensionnotsupportedbyserver

my previous code is as follows:

def sendmail(receivers,mailtitle,mailcontent):

    ret=True
    # try:
    # msg=MIMEText(mailcontent,'plain','utf-8')
    msg = MIMEText(mailcontent, 'html', 'utf-8')
    msg['From']=formataddr(["I'm Black",sender]) # brackets correspond to sender's email nickname, sender's email account
    # msg['To']=formataddr(["Recipient nickname",receivers]) # The one in brackets corresponds to the recipient's email nickname, recipient's email account
    msg['Subject']=mailtitle # The subject of the message, also known as the title

    server = None
    # Determine if it is an SSL connection
    if flag_mail_ssl:
        server=smtplib.SMTP_SSL(mail_host, mail_port) # SMTP server in sender's mailbox
    else:
        server=smtplib.SMTP(mail_host, mail_port)#
    server.login(mail_user, mail_pass) # the brackets correspond to the sender's mailbox account, mailbox password
    server.sendmail(sender,receivers,msg.as_string()) # The brackets correspond to the sender's mailbox account, the recipient's mailbox account, and the sent mail
    server.quit()# close the connection
    # except Exception as e:# If the statement in try is not executed, the following ret=False will be executed
    # ret=False
    return ret

After searching the Internet, add the following two lines of code before login:

server.ehlo() # Send SMTP 'ehlo' command to Gamil
server.starttls()

That’s it. The final code is:

def sendmail(receivers,mailtitle,mailcontent):
    ret=True
    # try:
    # msg=MIMEText(mailcontent,'plain','utf-8')
    msg = MIMEText(mailcontent, 'html', 'utf-8')
    msg['From']=formataddr(["I'm Black",sender]) # brackets correspond to sender's email nickname, sender's email account
    # msg['To']=formataddr(["Recipient nickname",receivers]) # The one in brackets corresponds to the recipient's email nickname, recipient's email account
    msg['Subject']=mailtitle # The subject of the message, also known as the title

    server = None
    # Determine if it is an SSL connection
    if flag_mail_ssl:
        server=smtplib.SMTP_SSL(mail_host, mail_port) # SMTP server in sender's mailbox
    else:
        server=smtplib.SMTP(mail_host, mail_port)#
    server.ehlo() # Send SMTP 'ehlo' command to Gamil
    server.starttls()
    server.login(mail_user, mail_pass) # The corresponding mailbox account and mailbox password in parentheses is the sender's mailbox
    server.sendmail(sender,receivers,msg.as_string()) # The mail accounts in parentheses are the sender's mailbox account, the recipient's mailbox account, and the sent mail
    server.quit()# close the connection
    # except Exception as e:# If the statement in try is not executed, the following will be executed ret=False
    #     ret=False
    return ret