NameError:未定义名称“数据”

时间:2018-04-17 01:44:17

标签: python-3.x

我将答案复制到此堆栈溢出问题Decoding base64 from POST to use in PIL 即:

from PIL import Image
from io import BytesIO
import base64

data['img'] = '''R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==''' 

im = Image.open(BytesIO(base64.b64decode(data)))

并在我的文本编辑器中运行并继续说数据未定义但我无法弄清楚原因。

2 个答案:

答案 0 :(得分:2)

删除from PIL import Image from io import BytesIO import base64 data = '''R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==''' im = Image.open(BytesIO(base64.b64decode(data)))

line
    ^self, String lf

答案 1 :(得分:0)

只需在DROP TABLE PLAYER_TABLE1 DECLARE @Player NVARCHAR(50); DECLARE @columns NVARCHAR(max); DECLARE @sql NVARCHAR(max); DECLARE @columns2 NVARCHAR(max); DECLARE @sql2 NVARCHAR(max); SET @player='cagri' SET @columns = Stuff((SELECT ',' + Quotename(Rtrim(Ltrim(x.columns))) FROM (SELECT COLUMN_NAME as columns FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME= 'PLAYER_TABLE' and COLUMN_NAME<>'PLAYER_NAME' ) AS x ORDER BY X.columns FOR xml path('')), 1, 1, ''); SET @sql = N' SELECT PLAYER_NAME, Un_Pivot.Field, Un_Pivot.Value INTO PLAYER_TABLE1 FROM ( SELECT * FROM PLAYER_TABLE ) Data UNPIVOT ( Value FOR Field IN ('+@columns+') ) AS Un_Pivot'; EXECUTE sp_executesql @sql; SET @columns2 = Stuff((SELECT ',' + Quotename(Rtrim(Ltrim(y.Field))) FROM (SELECT Field FROM PLAYER_TABLE1 WHERE VALUE<>0 AND PLAYER_NAME=@Player) AS y ORDER BY y.Field FOR xml path('')), 1, 1, ''); SET @sql2 = N'SELECT PLAYER_NAME,'+@columns2+'FROM PLAYER_TABLE WHERE PLAYER_NAME='+char(39)+@Player+char(39); EXECUTE sp_executesql @sql2 之前添加data = dict()即可。在使用括号运算符访问dict键之前,需要将data['img'] = ...定义为dict。