English 中文(简体)
字型色色 : 需要字符缓冲
原标题:typeerror: character buffer expected

下面是我代码中的一个部分, 我正在试图输出一个字符串和一个整数到文件。 它不会让我每次输出更多, 所以不得不把它们放在分隔线上。 我现在也有一个错误:

TypeError: Expected a character buffer object

referring to the line outputting the variable count. Can someone tell me how to fix this error? Also if I could somehow combine all this into one line that would be cool too. Thanks!

print outfile.write ("(" + currentuser + ")")
print outfile.write (" ")
print outfile.write (count)
问题回答

文件对象的 .write () 方法需要一个字符串参数。 要写入整数, 您需要先将其转换为字符串 。

outfile.write("(%s) %s" % (currentuser, count))

可能是您正在寻找的东西。 我不清楚您为什么重新使用 < code> print 来显示返回值, 因为 < code>. write () 没有返回任何信息 。

如果这是Python(我不确定),请尝试

print outfile.write ("(" + currentuser + ") " + str(count))

print outfile.write("(%s) %d" % (currentuser, count))

print outfile.write("({0}) {1}".f或mat(currentuser, count))




相关问题
Converting an Integer to Enum in PostgreSQL

I have created a custom data type enum like so: create type "bnfunctionstype" as enum ( normal , library , import , thunk , adjustor_thunk ); From an external data ...

How to display integers in messagebox in Visual C#?

I am trying to use a messagebox to debug a Visual C# program. When I click a button I want a simple messagebox to popup and display the values of several integer variables. This is what I have ...

makes pointer from integer without a cast

i have a simply warning in my iphone dev code. NSUInteger *startIndex = 20; This code work, but i have a warning : warning: passing argument 1 of setStartIndex: makes pointer from integer without ...

C# testing to see if a string is an integer?

I m just curious as to whether there is something built into either the C# language or the .NET Framework that tests to see if something is an integer if (x is an int) // Do something It seems to ...

Performance of 32-bit integers in a 64-bit environment (C++)

We ve started compiling both 32- and 64-bit versions of some of our applications. One of the guys on my project is encouraging us to switch all of our 32-bit integers to their 64-bit equivalents, ...

How to handle Facebooks new UID sizes?

I ve been working a little bit on a Facebook application, but when I registered a new user to test the friend interaction the new user got a uid (100000XXXXXXXXX) that seems to big for php to handle. ...

Storing ints in a Dictionary

As I understand, in Objective-C you can only put Objects into dictionaries. So if I was to create a dictionary, it would have to have all objects. This means I need to put my ints in as NSNumber, ...

热门标签