Cuma, Mart 21, 2008

Grubi duzeltme



GRUB acilis yoneticiniz herhangi bir nedenden oturu hasar gorduyse
(ornegin; diskin bir bolumunde Linux varken bos bir bolume Windows
kurdugunuzda acilis yoneticiniz buyuk olasilikla size Linux 'unuzu
gostermeyecektir) herhangi bir Linux dagitiminin LiveCD 'sini sisteme
takin ve LiveCD 'deki Linux acildiktan sonra bir terminalde asagidaki
komutlari calistirin:



# grub

grub > root (hd0, X)

grub > setup (hd0)

quit

#



X: Linux bolumunuzun bulundugu disk bolumudur ve 1, 2, 3 gibi bir tam sayidir.
http://ipucu.enderunix.org/view.php?id=1875

Salı, Mart 18, 2008

Writing Unicode Characters in Python

Unicode files and Python



Reading and writing Unicode files from Python is simple. Use
codecs.open() and specify the encoding.



  import codecs
# Open a UTF-8 file in read mode
infile = codecs.open("infile.txt", "r", "utf-8")
# Read its contents as one large Unicode string.
text = infile.read()
# Close the file.
infile.close()

http://www.jorendorff.com/articles/unicode/python.html

Python UnicodeDecode

If you get an error like this
>> bytestring = '\xc3\xa4'     # Uuh, some non-ASCII bytestring!
>>> german_ae += bytestring
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0:
ordinal not in range(128)
then you must do
german_ae.decode('latin1').
here is the discussion
http://www.onlamp.com/pub/a/python/excerpt/pythonckbk_chap1/index.html



Salı, Mart 04, 2008

Python file handling


From Python documentation:
----------------
write( str)

Write
a string to the file. There is no return value. Due to buffering, the
string may not actually show up in the file until the flush() or
close() method is called.
----------------

Thus flush()
should be used before reading any information just written to a file
moreover seek() should be used to reposition the file pointer thus the code should be changed as follows:

f = open('c:/test.txt','w+') # open file for updating
f.write('Hello World') # write some text to it
f.flush() # flush the internal buffer
f.seek(0) # reposition file pointer to beginning of file This is important when you need to rewind the pointer
f.read() # read the text that was just written