Oracle, Web, Script, SQLserver, Tips & Trick

November 24, 2010

Phyton

Filed under: phyton — sikathabis @ 9:48 pm
Tags:
- Format Angka
'{:1,.2f}'.format(123.0) menjadi '123.00'
'{:7,.1f}'.format(123.0) menjadi ' 123.0'
'{:8,d}'.format(123.0) menjadi '1,200.00'

import sys
try:     f = open('myfile.txt')     s = f.readline()     i = int(s.strip()) except IOError as (errno, strerror):     print "I/O error({0}): {1}".format(errno, strerror) except ValueError:     print "Could not convert data to an integer." except:     print "Unexpected error:", sys.exc_info()[0]     raise

1 Comment »

  1. import zlib
    import sys
    def baca_text(fname):
    try:
    f=open(fname,”r”)
    content=f.read()
    f.close()
    return content
    except:
    print “Error ketika file dibaca”
    return -1
    def compress(string):
    ret=zlib.compress(string)
    return ret
    def decompress(string):
    ret=zlib.decompress(string)
    return ret
    if __name__==”__main__”:
    argumen1=sys.argv[1]
    jumlah_argumen=len(sys.argv)
    if argumen1==”compress”:
    if jumlah_argumen!=4:
    print “penggunaan : python ” +
    sys.argv[0] + ” ”
    else:
    namafile_input=sys.argv[2]
    namafile_output=sys.argv[3]

    finput=open(namafile_input,”r”)
    strinput=finput.read()
    finput.close()
    stroutput=compress(strinput)

    foutput=open(namafile_output,”wb”)
    foutput.write(stroutput)
    foutput.close()
    if argumen1==”decompress”:
    if jumlah_argumen!=4:
    print “penggunaan : python ” +
    sys.argv[0] + ” ”
    else:
    namafile_input=sys.argv[2]
    namafile_output=sys.argv[3]

    finput=open(namafile_input,”r”)
    strinput=finput.read()
    finput.close()
    stroutput=decompress(strinput)

    foutput=open(namafile_output,”wb”)
    foutput.write(stroutput)
    foutput.close()
    if argumen1==”bacafile”:
    if jumlah_argumen!=3:
    print “USAGE : python file.py

    else:
    print sys.argv[2]

    isi_file=baca_text(sys.argv[2])
    if isi_file!=-1:
    print isi_file

    Comment by sikathabis — March 8, 2011 @ 6:12 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Teknologi Pendidikan

Just another WordPress.com weblog

KATAKAMI

Jurnalisme Yang Dapat Dipercaya

Tonk Kosonk Baonk Bunyinya

Penampungan Serapah Tanpa Sumpah

Qey050489's Blog

Ayo Bangkit sobat..!!!!!

B. S. Totoraharjo

Orang Bodoh Yang Tak Kunjung Pandai

culturekitchen foodlab

New Food and Art in Yogyakarta

Wahyu Catur Wibowo

Musafir Dunia Maya

SQL.... Still Learning

My Reference on SQL Server

neinframe

Street Photography is like a box of a chocolates, you're never know what you're gonna get - Thomas Leuthard -

Keluarga Andrivito

-- Andrivito's Journal --

DRK™

This site is about Latest NEWS, Articles, Videos, Books, Course, Presentations, Tips & Tricks related to I.T Pro's

Gaurav Saxena

|| तत् त्वम् असि ||

Be a good Moeslim

Menuju Pribadi Muslim Sejati yang Bertaqwa

TuanSUFI

Manajemen Sholat, renungan spiritual, Teknologi Informasi

Pelangi di khatulistiwa....

Mari berbagi kebaikan, pengalaman dan senyum denganku

angkasa13

Ceritanya saya, Pikirannya saya, Hatinya saya

sikathabis

sikathabis semua informasi disini

%d bloggers like this: