For future reference, you do not want to assume that the characters you search for are found. This is better IMHO, although I too would prefer to use .split(".")
if start == -1:
break
najdi = DB.find ('.', start)
if najdi > -1:
end = DB.find ('.', najdi)
if end > -1:
br = DB[start:najdi:end]
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
zachabesh meant something like this, using 2 splits per record
test_data = [
"2001.7.1.407 изутрината во тетовски\n",
"2003.5.3.20083 кзк ја штити таканаречен\n",
"2001.6.1.407 test rec #1\n",
"2003.10.3.20083 test rec #2\n",
"2001.11.7.1830 винарските визби во македонија и оваа година\n"]
for rec in test_data:
rec=rec.strip()
dots_split = rec.split(".")
print "\ndots_split =", dots_split
if len(dots_split) > 3:
print "year=%s, month=%s, catagory=%s" % \
(dots_split[0], dots_split[1], dots_split[2])
space_split = dots_split[3].split()
if len(space_split) > 1:
print " id=%s, name=%s" % (space_split[0], " ".join(space_split[1:]))
else:
print "space split error", dots_split[3]
else:
print "data error", rec
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
You can use string_var.isdigit() and string_var.isalpha(), or use a try/except.
try:
float_var=float(string_var)
print float_var, "is a number"
except:
print string_var, "is a string"
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714