Python中文
首页
教程
问答
标签
搜索
登录
注册
类型错误:强制转换为Unicode:需要字符串或缓冲区,找到类型
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在尝试编写一个代码来读取一个文件并对其进行一些操作。</p> <p>代码:</p> <pre><code>def assem(file): import myParser from myParser import Parser import code import symboleTable from symboleTable import SymboleTable newFile = "Prog.hack" output = open(newFile, 'w') input = open(file, 'r') prsr=Parser(input) while prsr.hasMoreCommands(): str = "BLANK" if(parser.commandType() == Parser.C_COMMAND): str="111"+code.comp(prsr.comp())+code.dest(prsr.dest())+code.jump(prsr.jump())+"\n" output.write(str) prsr.advance() </code></pre> <p>我得到的错误是:</p> <pre><code>Traceback (most recent call last): File "assembler.py", line 11, in <module> input = open(file, 'r') TypeError: coercing to Unicode: need string or buffer, type found </code></pre> <p>如何运行程序:</p> <pre><code> python assembler.py Add.asm </code></pre> <p>其中Add.asm id是我要读取的文件,所有模块都在同一个库中,包括.asm文件。</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<blockquote> <p>File "C:\Python27\lib\ntpath.py", line 488, in abspath path = _getfullpathname(path) TypeError: coercing to Unicode: need string or buffer, builtin_function_or_method found</p> </blockquote>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何用if条件捕获函数返回值
9 回答
如何用if语句判断列表中是否存在该索引?
6 回答
如何用if语句向量化numpy数组中的最大值?
8 回答
如何用IF语句有条件地保存零碎的结果?
5 回答
如何用if语句测试异常对象?
10 回答
如何用IF语句编写二元函数
7 回答
如何用igraph在python中创建顶点权重的图?
5 回答
如何用ijson和python解析json
2 回答
如何用iloc求子矩阵
1 回答
如何用Imagemagick或PIL绘制高质量的图像笔划(边框)?
7 回答
如何用importlib在python中动态导入模块?
8 回答
如何用import语句重写python内置函数?
10 回答
如何用imshow混合裁剪的强度并显示正确的混合强度?
8 回答
如何用in dictionary解析havin dictionary中的json文件
7 回答
如何用in-Django URL替换%20
9 回答
如何用in\op正确构造查询
4 回答
如何用inbuild对象替换文件
10 回答
如何用inheritan类实现flask restful
4 回答
如何用intersphinx正确地编写对外部文档的交叉引用?
10 回答
如何用int修改LpVariable?
3 回答