Author Archives: Robins

python keyerror(0)


It’s not the key of the keyboard, it’s the key of the dict
When dict is evaluated, the key does not exist in the key() of dict, and an error is reported

When python reads key and value, if key does not exist, it will trigger KeyError error, as follows:

Python

t = {
    'a': '1',
    'b': '2',
    'c': '3',
}
print(t['d'])

It will appear:

KeyError: 'd'

The first solution
First, test whether the key exists, and then proceed to the next operation, such as:

Python

t = {
    'a': '1',
    'b': '2',
    'c': '3',
}
if 'd' in t:
    print(t['d'])
else:
    print('not exist')

There will be:

not exist

The second solution
Use the built-in get(key[,default]) method dict; if key exists, return its value; otherwise return default; Using this method will never trigger KeyError, as follows:

Python

t = {
    'a': '1',
    'b': '2',
    'c': '3',
}
print(t.get('d'))

There will be:

None

Add default parameter:

Python

t = {
    'a': '1',
    'b': '2',
    'c': '3',
}
print(t.get('d', 'not exist'))
print(t)

There will be:

not exist
{'a': '1', 'c': '3', 'b': '2'}

The third solution
Using dict built-in setdefault(key[,default]) method, if key exists, return its value; Otherwise insert this key, its value is default, and return default; Using this method will never trigger KeyError, as follows:

Python

t = {
    'a': '1',
    'b': '2',
    'c': '3',
}
print(t.setdefault('d'))
print(t)

There will be:

None
{'b': '2', 'd': None, 'a': '1', 'c': '3'}

Add default parameter:

Python

t = {
    'a': '1',
    'b': '2',
    'c': '3',
}
print(t.setdefault('d', 'not exist'))
print(t)

There will be:

not exist
{'c': '3', 'd': 'not exist', 'a': '1', 'b': '2'}

The fourth solution
Add the /___ b> method to the class dict. If key does not exist, it goes to the missing__() method without firing KeyError, e.g.

Python

t = {
    'a': '1',
    'b': '2',
    'c': '3',
}


class Counter(dict):

    def __missing__(self, key):
        return None
c = Counter(t)
print(c['d'])

There will be:

None

Change return value:

Python

t = {
    'a': '1',
    'b': '2',
    'c': '3',
}


class Counter(dict):

    def __missing__(self, key):
        return key
c = Counter(t)
print(c['d'])
print(c)

There will be:

d
{'c': '3', 'a': '1', 'b': '2'}

The fifth solution
Using the collections.defaultdict([default_factory[...]]) object, which is actually inherited from the dict and is actually used with the missing__ __() method, its default_factory argument is passed to the missing__() method,
if default_factory is None, it will be the same as dict, it will trigger KeyError error, as follows:

Python

import collections
t = {
    'a': '1',
    'b': '2',
    'c': '3',
}
t = collections.defaultdict(None, t)
print(t['d'])

There will be:

KeyError: 'd'

But if you really want to return None is not out of the question:

Python

import collections
t = {
    'a': '1',
    'b': '2',
    'c': '3',
}

def handle():
    return None
t = collections.defaultdict(handle, t)
print(t['d'])

There will be:

None

If the default_factory parameter is a data type, it will return its default value, such as:

Python

import collections
t = {
    'a': '1',
    'b': '2',
    'c': '3',
}
t = collections.defaultdict(int, t)
print(t['d'])

There will be:

0

Such as:

Python

import collections
t = {
    'a': '1',
    'b': '2',
    'c': '3',
}
t = collections.defaultdict(list, t)
print(t['d'])

There will be:

[]

Note:
if dict contains dict, key nested to get value, if a middle key0 does not exist, then all the above methods are invalid, and 1 KeyError2 will be triggered:

Python

import collections
t = {
    'a': '1',
    'b': '2',
    'c': '3',
}
t = collections.defaultdict(dict, t)
print(t['d']['y'])

There will be:

KeyError: 'y'

ERP failure: Error when opening an RFC connection

Created by Jerry Wang, last modified on May 20, 2015 Created by Jerry Wang, when opening an Opportunity, the following error was encountered: this error message could only be seen when entering the Opportunity overview page for the first time. Root cause: An RFC ping operation within the ERP Component CLASS_CONSTRUCTOR(will only be executed together) : if Sy-Subrc is not 0, the error message will be displayed on the UI.

.

Solution to MySQL workbench error 1148 unable to load local data

Windows10 workbench 8.0 error code:1148 temporary solution is as follows :
1. In the Workbench, type Show Global variables like ‘local_infile’;
result should be :on. This problem has nothing to do with whether localinfile =1, which is a bug of workbench. 2. Continue to enter show variables like ‘secure_file_priv’;
the result should be C:\ProgramData\MySQL\MySQL Server 5.7\Uploads file; 3. Put the files that need to be imported into the file in step 2;
4. Load data local infile command to remove the local, and combined with step 2 folder path, for example, is as follows:
the load data infile ‘C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/a.c sv into table a’;
Ps: resources: https://bugs.mysql.com/bug.php?Id =91891 Post Catherine S reply, like one!

Securityerror: error ᦇ 2148: SWF file (SWF file cannot access local resources)

SecurityError: Error # 2148: SWF file file:///F:/work2010/tiger/rmpublisher.air/bin-debug/index.swf file:///F:/work2010/tiger/rmpublisher.air/bin-debug/plugins/plugins.xml cannot access the local resources. Only file system-limited SWF files and trusted local SWF files can access local resources.
at flash.net: : URLStream/load ()
at flash.net: : the URLLoader/load ()
the at com. Edlt. Utils: : Settings/loadSettings () [D:
Solutions:
The first:
Right click on flex project –& GT; properties–> ActionscriptCompiler–> Additional compiler arguments
plus “-use-network=false” is OK
SWF will not be able to access network resources such as socket communications.
So it’s better not to use it that way.
The second:
I have found a lot of articles on security sandbox on the Internet, most of which are about how to solve the problem of network resource access, which is different from what I want in this article. Although these articles do not address the issue of local resource access. The solution to this problem should be similar, with the network adding a trusted domain name in a cross or something file to allow access, then the local resource should also be able to add a local resource path somewhere to allow access.
The details are as follows: find system32\Macromed\Flash\FlashPlayerTrust in the Windows installation directory, create a text file in this directory, enter the detailed path of Flash to access local resources in the file, and save. Execute SWF, no more errors. OK
For example: in C:\WINDOWS\ System32 \Flash\FlashPlayerTrust directory to add a file, such as: 1. TXT (file name can be arbitrarily started), the file content is: “D:\demo\test\” that is the project path, of course, can also be set to “D:\”

Error c2259 cannot instance abstract class due to following members

Error description:
E:/mywork/1.7 sp1/ginfo/client/SRC/skdesigner/dsgquerydlg. H. (295) : error C2259: ‘CDsgFormatDataMgrDlg’ : Always instantiate the abstract class due to the following members:
e:/mywork/1.7 sp1/ginfo/client/SRC/skdesigner/dsgformatdatamgrdlg. H (14) : see declaration of ‘CDsgFormatDataMgrDlg’
 
Reason for error:
An implementation class inherits an abstract base class, but does not implement all the methods in the abstract base class.
 
Can be similarly implemented:
Virtual Void EnableControl(PSKOPEROBJECT Lpoo, BOOL bEnable) {}//
 
Code example:
 
class CDsgFormatDataMgrDlg : public CDialogImpl< CDsgFormatDataMgrDlg> ,
public ISkBusinessEngineSink// abstract base class
{
public:
enum {IDD = IDD_FORMATDATAMGR_DLG};

CDsgFormatDataMgrDlg ();
virtual ~ CDsgFormatDataMgrDlg ();
virtual BOOL PreTranslateMessage(MSG* pMsg);

}
 
The class ISkBusinessEngineSink
{
public:
virtual void HandleOneCSObject (LPCTSTR lpszName) {}
virtual BOOL HandleUpdateCalendarResult (int nType, PCALENDAREVENT lpce,
DWORD dwClientTmpId, BOOL bRet, DWORD dwErrorCode) {return FALSE; }
virtual BOOL HandleUpdateDesktopResult (int nType, PDESKTOPITEM lpdi,
DWORD dwClientTmpId, BOOL bRet, dwords dwErrorCode) = 0.

virtual void HandleHotBUList(PHOTBU LPHB, int nCount) {}
virtual void OnDBFuncReady(BOOL bReady) = 0;
virtual void OnDBViewReady(BOOL bReady) = 0;
virtual void OnSNReady(BOOL bReady) = 0;
virtual void OnTableReady(BOOL bReady) = 0;

}
 
Methods in the abstract base class must fully implement…
Appendix:
The choice of http://www.cnblogs.com/shenfx318/archive/2007/01/25/630760.html (abstract base classes and interfaces) and the difference between
http://www.cnblogs.com/TravelingLight/archive/2010/06/02/1750073.html (abstract base class for some of the problems)
http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Companion/cxx_crib/interfaces.html
(OO concepts and abstract classes and interfaces)
 

Error: 17053 LogWriter: Operating system error 21(The device is not ready.)

An error occurred while Detach database was running today, DBCC CHECKDB saw the following information from the SQL Server error log:
 
Error: 17053, Severity: 16, State: 1.
LogWriter: Operating system error 21(The device is not ready.)encountered.
Write error during log flush.
Error: 9001, Severity: 21, State: 4.
The log for database ” is not available.Check the event log for related error messages. Resolve any errors and restartthe database.
Error: 823, Severity: 24, State: 2.
The operating system returned error 21(The device is not ready.) to SQLServer during a read at offset 0x000000000de000 in file ‘xx.mdf’. Additional messages in the SQL Server error log and system eventlog may provide more detail. This is a severe system-level error condition thatthreatens database integrity and must be corrected immediately. Complete a fulldatabase consistency check (DBCC CHECKDB). This error can be caused by manyfactors; for more information, see SQL Server Books Online.
 
According to error 21, there should be a disk problem, but this disk has a lot of other databases on it that will work, and the newly created files will be fine.
 
Then I saw the error of 823, which should be caused by a hardware error. Microsoft’s recommendation is to run DBCC CHECKDB. But it doesn’t work at all.
 
Trying to run DBCC CHECKDB WITH TABLOCK still reports an error.
 
Then I tried to restart the service once, and the database worked. Running DBCC CHECKDB found no errors.
 
Feel this problem is very bogey, in the hardware disk is no problem even reported disk error.
 
 

VS2010 library function problem: objidl. H (11266): error c2061: syntax error: identifier ‘__ RPC__ out_ xcount_ part’

This error was caused by the lack of lib files or include, but the UI in VS2010 was set up so badly that people didn’t know how to edit the original VC++ directory files. The solution is as follows:
Open the VS2010 project
Notice that in the lower left corner are Solution Explorer, Class View, Property Manager, and many other options.
is revised for Directories like the one we introduced in VS2010.

display Property Manager
contains the Debug|Win32 and Release|Win32 options
. You can set the project properties of Debug and Release
. Open any of them
. Double click microsoft.cpp.win32.
is modified here for the tutorial vc Directories. H (11266) : error C2061: syntax error: identifier ‘___, rpc___, out_xcount_part’
use the above method to delete the DirectX SDK Include from the Include path. Supplements: the

Directories that were modified for VC++ Directories in the project property dialog are project specific. The above modified VC++ Directories are large, affecting all project Directories and configuration Directories (Debug/Release/…) .

SOE deployment error ClassFactory cannot supply requested class

The original link: http://www.cnblogs.com/myyouthlife/p/3284291.html

Problem description:
An error message appears when the deployed SOE is enabled for a service. If the newly deployed SOE is enabled for SampleWorldCities, the error message is as follows:
service failed to start
SampleWorldCities.MapServer:

ClassFactory cannot supply requested class
 
Causes:
This error message usually appears in.NET SOE because.NET extension support was not enabled when ArcGIS Server was installed.
Solutions:
Fix arcGIS Server, enable.NET support. The screenshot below

==== dividing line ===
Update 9.29 days
In addition to the above, there is another situation in which the arcobjects SDK that is adopted by the opening of SOE is issued with the wrong version and the arcobjects SDK that is owned on the deployment machine. For example, the ARcobjects SDK for.NET 10.2 is adopted for soe development and deployed on a 10.1 Server machine, and only the Arcobjects SDK for.NET 10.1 is on the machine. The above error will also occur

iPhone on Windows 10: “Device is unreachable” SOLVED [Debug]

    Disconnect your iPhone/iPad from your computerGo to Settings on your iOS deviceOpen Photos and scroll to the bottomUnder ‘Transfer to Mac or PC’, chang efrom Automatic to Keep Originals (“Automatically transfer photos and videos in a compatible format, or always transfer the original file without checking for compatibility.”)

Now connect again the device to the Windows 10 computer and copy/paste the files again; it should work fine now!

iPhone connected to Windows 10 computer. iTunes is not a necessity to be installed when copying files from one to the other.