File object is referenced as string

Please post any questions about developing your plugin here. Please use the search function before posting!
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

File object is referenced as string

Postby arawra » Fri May 09, 2014 5:43 pm

Not sure why my fileObj variable is being referenced as a string.

TypeError: 'str' doesn't support buffer interface

Code: Select all

@SayCommand('!test')
def test(player, teamonly, CCommand):
    fileObj = open('test.txt','wb')
    for x in dir(PlayerEntity):
        fileObj.write(x) #error here
    fileObj.close()
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri May 09, 2014 5:57 pm

You need to open in "w" mode not "wb". Also, use context management:

Syntax: Select all

@SayCommand('!test')
def test(player, teamonly, command):
with open('test.txt', 'w') as fileObj:
fileObj.write(x + '\n')


Also:
http://www.sourcepython.com/showthread.php?527

No more need to use "code" blocks when Python syntax blocks work.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 49 guests