My apologies Python Gurus for repeating this request for read, write, split and 
append from a text file in notepad.  I worked on it till late last night and 
will again today.  I can't seem to get past trying to write the names to one 
list and the numbers (converted to integers) to the other.  My lists come up 
empty.

I am a full-time firefighter that taught myself to use ArcGIS to make maps and 
now am in school so I can move into emergency mgmt.  I can't seem to teach 
myself Python and I am really trying.
thank-you,

LN


>>> filename = "C:/Python27/egund919/Program1/BOJ.txt"
>>> myfile = open(filename,"r")
>>> newfile = "C:/Python27/egund919/Program1/BOJ_B.txt"
>>> mynewfile = open(newfile,"w")
>>> while True:
 line = myfile.readline()
 print line
 mynewfile.write(line)
 if not line: break
 
States OJ
AK 36
AL 39
AR 39
AZ 45
CA 61
CO 54
CT 61
DC 93
DE 62
FL 51
GA 47
HI 72
IA 54
ID 36
IL 62
IN 50
KS 41
KY 41
LA 40
MA 62
MD 62
ME 58
MI 57
MN 54
MO 49
MS 43
MT 47
NC 50
ND 45
NE 41
NH 54
NJ 57
NM 57
NV 55
NY 62
OH 51
OK 34
OR 57
PA 55
RI 63
SC 45
SD 45
TN 42
TX 44
UT 34
VA 53
VT 67
WA 58
WI 56
WV 43
WY 33

>>> myfile.close()
>>> infile = open('C:/Python27/egund919/Program1/BOJ_B.txt','r')
>>> import string
>>> state_name = []
>>> data_value = []
>>> counter = 0
>>> x = 0
>>> line = infile.readline()
>>> while True:
              line = infile.readline()
              if not line: break
              counter = counter + 1
              States, OJ = string.split(line)
              XSTATES = str(States)
              XNUM = int(OJ)
              state_name.append(XSTATES)
              data_value.append(XNUM)
 
>>> len(counter)
Traceback (most recent call last):
  File "<pyshell#29>", line 1, in <module>
    len(counter)
TypeError: object of type 'int' has no len()
>>> counter.count
Traceback (most recent call last):
  File "<pyshell#30>", line 1, in <module>
    counter.count
AttributeError: 'int' object has no attribute 'count'
>>> len(state_name)
0
>>> list.state_name
Traceback (most recent call last):
  File "<pyshell#32>", line 1, in <module>
    list.state_name
AttributeError: type object 'list' has no attribute 'state_name' 
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to