This question relates to this one: Python app which reads and writes into its current working directory as a .app/exe
I got the path to the .txt file fine however now when I try to open it and read the contents it seems that it doesn't extract the data properly.
Here's the relevant code:
def getLines( filename ):
path = Cocoa.NSBundle.mainBundle().bundlePath()
real_path = path[0: len(path) - 8]
print real_path
f = open(real_path + filename, 'r') # open the file as an object
if len(f.read()) <= 0:
lines = {} # list to hold lines in the file
for line in f.readlines(): # loop through the lines
line = line.replace( "\r", " " )
line = line.replace( "\t", " " )
lines = line.split(" ") # segment the columns using tabs as a base
f.close() # close the file object
return lines
lines = getLines( "raw.txt" )
for index, item in enumerate( lines ): # iterate through lines
# ...
These are the errors I'm getting:
- 30/09/2012 10:28:49.103 [0x0-0x4e04e].org.pythonmac.unspecified.main: for index, item in enumerate( lines ): # iterate through lines
- 30/09/2012 10:28:49.103 [0x0-0x4e04e].org.pythonmac.unspecified.main: TypeError: 'NoneType' object is not iterable
I kind of understand what the errors mean however I'm not sure why they are being flagged up because if I run my script with it not in a .app form it doesn't get these errors and extracts the data fine.