2

I have a python program that basically parses through some CSVs and prints out a line and then stops until the user hits enter. Here is the full code:

#!/usr/bin/python

import os
import csv
import sys
from datetime import datetime

teams = [[] for x in xrange(0, 400)]
counter = 0

with open('t26.csv', 'rb') as f:

    next(f)

    reader = csv.reader(f)

    for row in reader:
        if row:
            if row[1] <> "" and row[1] <> "TEAM AVERAGES:":
                teams[counter].append(row[16])
                teams[counter].append(row[3])
                teams[counter].append(row[0])
                teams[counter].append(row[4])
                counter += 1


for i in range(0, counter - 1):
    diff = False
    lastTeam = ""
    firstDate = ""

    eid = teams[i][0]
    date = teams[i][1]
    team = teams[i][2]
    pc = teams[i][3] 


    for csvfile in os.listdir('Uploads'):
        with open('Uploads/' + csvfile, 'rb') as f:
            reader = csv.reader(f)

            team_index = 0
            eid_am_index = 0
            eid_pm_index = 0
            find = False

            for row in reader:

                index = 0
                for column_name in row:
                    if "team" == column_name:
                        team_index = index
                    if "eid_am" in column_name:
                        eid_am_index = index
                    if "eid_pm" in column_name:
                        eid_pm_index = index
                    index += 1


                if eid in row:
                    #print row[team_index] + ', ' + row[eid_am_index] + ', ' + row[eid_pm_index] + ', ' + ' ----> ' + csvfile
                    if row[team_index] <> lastTeam and lastTeam <> "":
                        diff = True
                    lastTeam = row[team_index]
                    if firstDate == "":
                        firstDate = csvfile
                    break


    if diff:
        print "\n*diff"
    else: #teams are the same
        team = team[5:]

        if "(" in team:
            team = team[:team.index('(') - 1]

        try:
            lastTeam = lastTeam[:lastTeam.index(' ')]
        except:
            g = 0
        print "\n*no diff: " + eid + " --> " + firstDate + " | " + date + "\tTeam: " + team + " | " + lastTeam + "\tPC: " + pc
        if team <> lastTeam and lastTeam <> "":
            print "*(!) teams not equal"

        f = raw_input('') #read user input and do nothing with it

I run this program on Bash on Ubuntu on Windows, and sometimes the symbols "^@" will pop up randomly on the terminal, and then when I click enter I get an error.

Here's an example of what the terminal looks like (with some #comments to explain):

*no diff: 4903 --> 6-27-2017 3_44_01 PM.csv | 8/1/2017 1:56:39 PM       Team: 180-A | 180-A     PC: AGENT3-102 #this line is printed out by the python program
^@ #this randomly show up
Traceback (most recent call last): #when i hit enter i get this error
  File "parse.py", line 127, in <module>
    f = raw_input('')
EOFError

Here's a screenshot as well: enter image description here

obl
  • 1,799
  • 12
  • 38
  • 2
    `^@` represents a null-byte (aka `\x00`), which is somehow making it to your `stderr` or `stdout`. The `EOFError` is probably raised when your `stdin` is being closed for some reason. I'd suspect a bug in bash for windows. – user2722968 Sep 03 '17 at 08:06

0 Answers0