I had no idea that there was any effort behind unicode strings in python. I thought all I'd have to do was put a 'u' before the strings when I first declared them. Good fun. Hopefully I haven't missplaced an error like last time. I'm fairly sure this is good to go though.
Code could be a little more compact, a few lines could be combined into something smaller, but I think this is easier on the eyes.
PHP Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# coding=UTF-8
Hindi=u"हिन्दी"
Sanskrit=u"संस्कृता वाक"
langs=[]
inputText="" # incase of IOError
try: inputText=open('bhaarat.text','r').readlines()
except IOError: print "Whoa whoa, where's your bhaarat.text?"
for items in inputText:
langs.append(items.split('. ')[1].split('\n')[0])
outputText=u""
att=0 # Generic counter
for items in langs:
if items[0].lower() == 's' or items[0].lower() == 'h':
if items.lower() == 'hindi': outputText += "%i. %s (%s)\n" %(att,items,Hindi)
elif items.lower() == 'sanskrit': outputText += "%i. %s (%s)\n" %(att,items,Sanskrit)
else: outputText+="%i. %s\n" %(att,items)
att+=1
open('out.text','w').write(outputText.encode("UTF-8"))
if inputText[-1].startswith('23'): None # Don't want to do this more then once
else: open('bhaarat.text','a').write("23. English")
Bookmarks