Python Forum
How do I use tabs and spaces? (how to resolve error TabError: inconsistent)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I use tabs and spaces? (how to resolve error TabError: inconsistent)
#7
(May-20-2021, 04:46 PM)Onanism Wrote: TypeError: a bytes-like object is required, not 'str'
When you make writer it's bytes because of wb.
Then nrow need to bytes as can not mix string and bytes one of the big changes when moving to Python 3 from 2.
So convert before write.
>>> nrow = 'hello world'
>>> type(nrow)
<class 'str'>
>>> nrow = nrow.encode() # Same as encode('utf-8')
>>> type(nrow)
<class 'bytes'>
The other way is to make like this with w and use encoding(default is utf-8),but should specify like this as eg OS can mess it some times.
ofile = open(self.ofname, "w", encoding='utf-8')
writer = csv.writer(ofile, delimiter=',', 
Reply


Messages In This Thread
RE: How do I use tabs and spaces? (how to resolve error TabError: inconsistent) - by snippsat - May-21-2021, 04:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with removing spaces and tabs from a string msqpython 14 4,076 Jan-21-2021, 10:48 PM
Last Post: deanhystad
  How Can I Resolve This Error JayJayOi 10 7,438 Jan-18-2018, 02:59 PM
Last Post: JayJayOi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020