Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assert failure
#1
We are supposed to write file out.

This is what I have and I am still getting an assertion failure:
with open('employee_salaries.tsv', 'w') as f_out:
  template = '{name},\t{salary}'
  for row in employee_table:
      sentence = template.format(name = row[0], salary = row[3])
      print(sentence)
      f_out.write(sentence +'\n')
Here is the assert test:
Error:
assert open('employee_salaries.tsv').read() == 'NAME\tEMPLOYEE ANNUAL SALARY\nBATEMAN, KELLY ANNE\t$118404.00\nCREMINS, KEVIN M\t$77238.00\nDAVIS, CRAIG W\t$77238.00\nMORENO, JOSE\t$120228.00\nURSETTA, ROSARIO\t$51216.00'
buran write Sep-03-2021, 05:24 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
We don't know what employee_table is and what data there are in it. Do you have the header in it? Also the expected output does not have comma (like your template) just tab. show what your generated file looks like.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Failure to run source command middlestudent 2 656 Sep-22-2023, 01:21 PM
Last Post: buran
  Dickey Fuller failure Led_Zeppelin 4 2,529 Sep-15-2022, 09:07 PM
Last Post: Led_Zeppelin
  xml decoding failure(bs4) roughstroke 1 2,210 May-09-2020, 04:37 PM
Last Post: snippsat
  SCIKIT learn failure in mac Perja11 1 2,255 Nov-30-2019, 06:44 PM
Last Post: snippsat
  Assert that dictionary contains a key phpMick 3 38,078 Nov-27-2019, 11:36 AM
Last Post: buran
  assert Naito 1 1,994 Jan-16-2019, 05:06 PM
Last Post: ODIS
  failure to find modules justus123 2 4,197 Dec-14-2018, 04:28 PM
Last Post: nilamo
  LIB install failure Able98 2 3,882 Jun-07-2017, 06:41 PM
Last Post: Able98

Forum Jump:

User Panel Messages

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