Helallinux Com

download Helallinux Com

of 12

Transcript of Helallinux Com

  • 7/23/2019 Helallinux Com

    1/12

    python 6.5

    English

    python 6.5:

    6.5.1 6.5.2

    6.5.3 6.5.4

    6.5.5 6.5.6

    modules/packages 6.5.7 6.5.8

    6.5.1 . byte code ( ) python

    redhat-config-* OOP

    }{

    .

    #!/usr/bin/python# hello.py - My 1st python applicationprint "Hello World!!"

    ;

    #

    script

    "

    "

    . \ .

    #!/usr/bin/python# quoting.py - quoted strings in pythonprint "you can put ' in side double quotes without a escape"print "you can't put \" in side double quotes without a escape"print 'you can put " in side single quotes without a escape'print 'you can\'t put \' in side single quotes without a escape'# \X1b ,\x1b, \X1B or \x1B (hex for ESC) and \033 for oct ESCprint "Visit us on \033[34,4mwww.daif.net/linux\033[0m"print 'Do \033[1mNOT\033[0m ignore \033[5mme\033[0m.'# put r or R in front of a quote to make it raw# in such case \n mean \n not new lineprint 'backslashs need to be esaped like "C:\\windows\\fonts"'print r'backslashs need NOT to be esaped in raw quotes like "C:\windows\fonts"'# two adjacent strings are like if they are one stringprint "what " "is " "your name ?"print ''' W E L C O M E T O 3 Q U O T E SThis type of quoting allow you to put " and ' or even "" withoutescaping, it can be a multi-line string without puting escapednewlines, it's very usefull for CGI too.'''print """ W E L C O M E T O 3 D O U B L E Q U O T E SSame as the previous but with double quotes"""

    integers Python27 0x1B ( x ) - ( ) long-integers

    L (bc ) long 033

    .27 ( ) .0xFFFFFFFEl l

    J

    (

    )

    0.3x10+9

    0.3e+9

    e

    0.3+1.9j j

    `` string conv ltr

    {} dictionary ltr

    -

    LinuxTodayLinux.org

    Linux.comSlashDot

    FreshMeatLWN.net

    ( )

    :

    :

    (

    )

    :

    Ubuntu . .

    :

    :

    :

    :// http

    Webwww.cltb.net

    Google

    Django Developerwww.allengeer.com

    Expert Django Developer Allen Geer,

    Software Engineer

    converted by Web2PDFConvert.com

    http://helallinux.com/ojuba-book/en/index.htmlhttp://helallinux.com/ojuba-book/en/index.htmlhttp://cltb.ojuba.org/downloads/http://cltb.ojuba.org/downloads/http://helallinux.com/ojuba-book/ar/articles/index.htmlhttp://www.thwab.net/http://helallinux.com/ojuba-book/ar/toc.htmlhttp://helallinux.com/ojuba-book/ar/toc.htmlhttp://helallinux.com/ojuba-book/ar/index.html#abouthttp://www.thwab.net/cgi-bin/ads.py?lang=enhttp://www.thwab.net/cgi-bin/ads.py?lang=enhttp://www.cltb.net/ar/articles/drool.htmlhttp://www.cltb.net/ar/articles/audio.htmlhttp://www.cltb.net/ar/articles/audio.htmlhttp://www.cltb.net/ar/articles/hijri.htmlhttp://distrowatch.com/http://distrowatch.com/table.php?distribution=arabianhttp://www.thwab.net/copyleft/free-sw-ar.htmlhttp://www.arabeyes.org/http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://www.thwab.net/cgi-bin/bugs.py?lang=en&site=http%3A%2F%2Fwww.cltb.net%2Far%2Fpython.htmlhttp://www.thwab.net/cgi-bin/ads.py?lang=enhttp://www.cltb.net/ar/articles/elephants.htmlhttp://www.cltb.net/ar/articles/drool.htmlhttp://www.cltb.net/ar/articles/scanner.htmlhttp://www.cltb.net/ar/articles/audio.htmlhttp://www.cltb.net/ar/articles/ubuntu.htmlhttp://www.thwab.net/anasheed/http://www.thwab.net/muhadhrat/http://www.cltb.net/ar/articles/hijri.htmlhttp://www.cltb.net/ar/articles/prayer.htmlhttp://distrowatch.com/http://linuxac.org/forum/forumdisplay.php?f=11http://joatha.org/http://distrowatch.com/table.php?distribution=arabianhttp://sourceforge.net/projects/arabian-linuxhttp://linuxac.org/forum/forumdisplay.php?f=10http://www.arabian-linux.com/http://distrowatch.com/table.php?distribution=ubuntumehttps://groups.google.com/group/ubuntumehttp://www.ubuntume.com/http://lwn.net/http://freshmeat.net/http://www.slashdot.org/http://www.linux.com/http://www.linux.org/http://www.linuxtoday.org/http://www.thwab.net/copyleft/osd-ar.htmlhttp://www.thwab.net/copyleft/free-sw-ar.htmlhttp://ar.wikipedia.org/http://www.thwab.net/http://www.linuxac.org/http://www.arabeyes.org/http://www.cltb.net/halloween/http://www.thwab.net/copyleft/http://helallinux.com/ojuba-book/ar/setup.htmlhttp://helallinux.com/ojuba-book/ar/whatis.htmlhttp://helallinux.com/ojuba-book/ar/rights.htmlhttp://helallinux.com/ojuba-book/ar/toc.htmlhttp://helallinux.com/ojuba-book/en/index.htmlhttp://cltb.ojuba.org/downloads/http://helallinux.com/ojuba-book/ar/articles/index.htmlhttp://www.thwab.net/http://helallinux.com/ojuba-book/ar/index.html#projectshttp://helallinux.com/ojuba-book/ar/toc.htmlhttp://helallinux.com/ojuba-book/ar/index.html#abouthttp://helallinux.com/ojuba-book/ar/php.htmlhttp://helallinux.com/ojuba-book/ar/toc.htmlhttp://helallinux.com/ojuba-book/ar/perl.htmlhttp://helallinux.com/ojuba-book/ar/index.html
  • 7/23/2019 Helallinux Com

    2/12

    [] list ltr

    () tuple ltr

    () functions call ltr

    [:] slicing ltr

    [ ] subscript access ltr

    . member access ltr

    ** rtl

    ~ ltr

    + - (

    )

    rtl* / %

    ltr

    + - ltr

    > ltr

    &

    '

    ' ltr

    ^ ( ( ltr

    | ^ ltr

    < > =

    == != ltr

    is ,is not ltr

    in ,not in ltr

    not

    ltr

    and ltr

    or ltr

    lambdalembda ( define/inline )

    myfoo(x,y): x+yltr

    perl printf print print print

    #!/usr/bin/python# print.py - some print tricksprint "Hello ",

    print "World!!"# print can do printf just put %print "look %8.3f" % 15.

    ( ( $ . float int

    #!/usr/bin/python# var1.py - how to use variablesmsg1 = "Hi! How are you today?"print "/\" * 10print msg1print "\/" * 10

    i = int(10.5)j = int("3")

    k = i/jprint "i = ", i, ",j = ", j, ",k = ", ka = float(10.5)b = float("3")c = a/bprint "a = ", a, ",b = ", b, ",c = ", c

    . raw_input

    #!/usr/bin/python# user-input.py - how to get input from the user.nm=raw_input("Enter your name: ")print "Hi", nmi=int(raw_input("Enter an integer: "))j=int(raw_input("Enter an integer: "))

    print " i + j =",i+jprint " i - j =",i-jprint " i * j =",i*jtry:print " i / j =",i/jexcept:print "Can't divide by zero!!"print "nice to meet you ",nm

    Generously Hosted by

    www.JadMadi.net

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://www.jadmadi.net/http://www.gnu.org/copyleft/http://www.linux.org/http://www.theopencd.org/
  • 7/23/2019 Helallinux Com

    3/12

    except ( ) try Python

    raise . ...[[EXCEPTIONS. ...[[EXCEPTIONS

    #!/usr/bin/python# python and exception handlingx=10try:v=float( raw_input("Enter the speed: ") )

    except:print "Error , you should enter a float number"print vtry:print x/vexcept ZeroDivisionError:print "Error , can't divide by zero"

    Python Tutorial td python cheatsheet Python Quick Reference html python

    6.5.2

    TAB

    :

    python

    block

    }{

    elif : ( ) if if . else

    #!/usr/bin/python# if1.py - simple ifi=int(raw_input("Enter an integer: "))# if the remainder is not zero then it's oddif (i % 2):print i," is odd"else:print i," is even"

    #!/usr/bin/python# if2.py - more about ifi=int(raw_input("Enter an integer less than 4 : "))if (i == 1):print "one"elif (i == 2):print "two"elif (i == 3):print "tree"else:print i," is NOT less than 4"

    for-in

    #!/usr/bin/python

    for i in (0,1,2,3,4,5):print ifor i in range(5):print i

    while

    #!/usr/bin/pythoni=1while (i

  • 7/23/2019 Helallinux Com

    4/12

    while (d>=1): if ( x % d) == (y % d) == 0 : return d else: d-=1a=int( raw_input("Enter a +ve integer: ") )b=int( raw_input("Enter a +ve integer: ") )print "The greatest common divisor is", \gcd(a,b)

    euler

    . =

    #!/usr/bin/python# default-arg.py - how to give an argument a default valuedef test(a="Hello",b="world"):print a,", ",b,"!!"test("Hi","Ahmad")test()test(b="Ahmad")

    6.5.3

    Tuple List 3 Sequence array String

    . ][ . -2 :

    #!/usr/bin/python# a is an arraya=[1,2,3,4,5]# you may say a=(1,2,3,4,5) or a=1,2,3,4,5print "a = ",aprint "the 1st one is ",a[0]print "the last one is ",a[-1]

    print "the 2nd to 4th elements are ",a[1:3]print "from the 2nd ",a[1:]print "to the 4th ",a[:3]print "a = ",a[:]# strings are arrays="Amman"print "Am[man] : ",s[2:]

    max min len

    #!/usr/bin/python# mean.py - calculate the mean of integersa=[]while (1):i=int( raw_input("Enter an integer (-1 to exit): ") )if (i==-1): breaka.append(i)print "you entered : ",aprint " max=",max(a),print " mix=",min(a)s=0for i in a:s+=iprint " sum=",s,print " sum=",float(s)/len(a)

    append

    LIST.[i:j]=LIST2LIST2 LIST j i /

    LIST.append(X)LIST X

    LIST.extend(LIST2)LIST LIST2

    LIST.insert(I,LIST2)I LIST LIST2

    LIST.index(X) LIST X

    LIST.count(X)LIST X

    del LIST.[i:j]LIST j i

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDF
  • 7/23/2019 Helallinux Com

    5/12

    LIST.pop([I]) LIST I

    LIST.remove(X)LIST X

    LIST.reverse()

    LIST.sort([FUNC])1 0 -1 FUNC LIST

    ( ) tuple

    #!/usr/bin/python# A tuple is a const array you can only addaTuple=(3.0,"two",1)

    print "the second is", aTuple[1]aTuple+=(0,)print "it's now", aTuple

    arrays : }{ .

    dict1={1 : "first","two" : "second"}

    hash

    # A dictionary is a hash (array accessed by a key)aDict={"key1":"val1","key2":"val2","key3":"val3"}

    for item in aDict.keys():print aDict[item], # to keep in the same lineprint # to end the line

    methods

    len(DICT)DICT

    del DICT[KEY]DICT

    KEY

    DICT.clear()

    DICT.value()DICT

    DICT.items()(KEY,VALUE) DICT

    DICT.keys()DICT

    DICT.has_key(KEY)KEY

    6.5.4

    import string string module Python

    STR.upper()

    STR.lower()

    STR.swapcase()

    STR.title()

    STR.capitalize()

    STR.strip()STR

    TAB

    STR.lstrip()STR

    TAB

    STR.rstrip()STR TAB

    STR.expandtabs([TABSIZE]) TABSIZE STR TAB

    STR.ljust(W)W STR

    STR.rjust(W)W STR

    STR.center(W)W STR

    STR.count(SUB[,START[,END]])STR SUB

    STR.find(SUB[,START[,END]])( 1 )- STR SUB

    STR.index(SUB[,START[,END]])try STR SUB

    STR.rfind(SUB[,START[,END]]) find

    STR.rindex(SUB[,START[,END]])

    index

    STR.replace(OLD,NEW[, MAX])NEW OLD

    STR.isalnum() STR

    STR.isalpha() STR

    STR.digit() STR

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDF
  • 7/23/2019 Helallinux Com

    6/12

    STR.islower() STR

    STR.isupper() STR

    STR.istitle() STR

    STR.isspace() STR

    STR.startswith(PREFIX[,START[,END]])PREFIX STR

    STR.endswith(SUFFIX[,START[,END]])SUFFIX STR

    STR.split([SEP[,MAX]]) SEP STR

    STR.splitlines([keepends]) STR

    STR.join(SEQ)STR

    SEQ

    split

    STR.encode([ENCODING[,ERRORS]]) ENCODING

    STR.translate(TABLE[,DELCHARS])STR TABLE

    perl printf %

    a="you have %05d trials." % 15print a

    . import re . RE python : .

    RE

    re.escape(STR)\

    STR escape

    re.compile(PAT[,FLAGS=0])re.S re.M re.L re.I 0 FLAGS PAT

    | re.X

    re.match(PAT,STR[,FLAGS]) STR PAT

    re.search(PAT,

    STR[,FLAGS]) STR PAT

    re.findall(PAT,STR)

    re.sub(PAT,NEW,

    STR[,COUNT=0]) NEW .STR NEW PAT

    re.subn(PAT,NEW,

    STR[,COUNT=0]) .

    re.split(PAT,STR[,MAX=0])

    .PAT

    STR. compile

    CPAT.match(STR[,POS][,ENDPOS])

    CPAT.search(STR[,POS][,ENDPOS])

    CPAT.findall(STR)

    CPAT.sub(NEW, STR[,COUNT=0])

    CPAT.subn(NEW, STR[,COUNT=0])

    CPAT.split(STR[,MAX=0])

    ( ( match

    pos index

    endpos. index

    re

    string

    #!/usr/bin/python# python and RE'simport restr1="This is a string and it's a good string"myre1=re.compile(r"^This") # a line starts with "This"myre2=re.compile(r"\b\w*ood\b") # a word end's with oodmyre3=re.compile(r"\bt\w*\b,",re.I) # a word start's with t or T (case insensitive)if (myre1.search(str1)):print "RE 1 ws found"if (myre2.match(str1)):print "RE 2 ws found"if (myre3.match(str1)):print "RE 3 ws found"r=myre3.findall(str1)print "number of RE 3 matches is ", len(r)print "and they are"for i in rprint i,

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDF
  • 7/23/2019 Helallinux Com

    7/12

    print

    \A. \b

    \B.[0-9] \d

    .[^0-9] \D.[ \t\n\r\f\v] \s

    .[^ \t\n\r\f\v]

    \S( ) \w. \W

    . \Z

    6.5.5

    execfile(FILENAME)FILENAME

    eval(STR)3 "( eval("1+2 STR

    input([PROMPT])raw_input([PROMPT])

    .

    PROMPT

    .

    range(START [,END[,STEP]])

    STEP

    END

    START

    xrange(START

    [,END[,STEP]]) STEP END START

    slice([START,] END

    [,STEP]) STEP END START ?! slice

    xrange(START

    [,END[,STEP]]) STEP END START

    reduce(FUNC,LIST) LIST FUNC

    len(OBJ)OBJ

    min(LIST)max(LIST)LIST

    cmp(X,Y)X-Y 1 0 -1

    abs(X)X

    round(X,N=0)

    N

    X

    pow(X,Y[,Z])

    Z

    Y

    X

    div(X,Y) X/Y

    chr(N)N

    ord(C)

    .

    C

    str(OBJ) OBJ

    int(OBJ) OBJ

    long(OBJ) OBJ

    float(OBJ)float OBJ

    oct(X) X

    hex(X)-

    X

    complex(X,Y)X+Yj

    list(SEQ) SEQ

    tuple(SEQ). tuple SEQ

    filter(FUNC,SEQ) FUNC SEQ

    6.5.6

    FILENAME (['open([FILENAME [,MODE='r ( ) ( ) MODE

    print [>> FILEOBJ,] [STR1 [,

    STR2 ]... [,]( ) F

    F.read([SIZE])( ) SIZE

    F.readline()

    F.write(STR) STR

    F.readlines()

    F.writelines(LIST) LIST

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDF
  • 7/23/2019 Helallinux Com

    8/12

    F.seek(OFFSET[,WHENCE=0]) OFFSET

    . 2 1 0 WHENCE

    F.tell()

    F.flush() buffer

    F.close()

    F.fileno()os fd

    F.isatty()TTY

    modules/packages

    6.5.7

    import MODULE

    . .string (dir(MODULE

    sys

    sys.argv [sys.argv[0

    .

    sys.exit(N=0)

    sys.exitfunc

    sys.platformos.name ( )

    sys.maxint

    sys.setdefaultencodin(ENCODING)

    ENCODING

    sys.getrecursionlimitsys.setrecursionlimit(N)

    os

    os.name

    os.error

    os.curdir"." -

    os.pardir".." -

    os.sep"/" "\\" -

    os.sep":" ";" - PATH

    os.linsep"n "\ "r\n "\ -

    os.environPATH -

    os.environ["PATH"]

    os

    ([os.mkdir(PATH[,MODEos.makedirs(PATH,[MODE=0777])

    MODE PATH

    (os.rmdir(PATHos.removedirs(PATH)

    PATH

    (os.unlink(PATHos.remove(PATH)

    ( ) PATH

    os.rename(OLDNAME,NEWNAME)shutil NEWNAME OLDNAME /

    os.chdir(PATH)os.getcwd()( cd pwd )

    os.listdir(PATH

    )PATH

    os.chmod(PATH,MODE)PATH

    os.stat(PATH)st_mtime st_atime st_size PATH

    st_gid st_uid st_ino st_ctime

    os.utime(PATH, (A,M) )

    M

    A PATH

    os.times()time

    os.open(FILE,FLAG, MODE) fd

    os.read(FD, N)N FD

    os.write(FD, STR)FD STR

    os.lseek(FD, POS,WHENCE)2 1 0 WHENCE POS FD

    os.close(FD)

    os._exit(N)sys.exit -

    -

    os.execv(PATH, ARGV)fork . ARGV PATH

    os.system(COMMAND)shell COMMAND

    os.pipe() w r -

    os.fork() /

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDF
  • 7/23/2019 Helallinux Com

    9/12

    os.popen(COMMAND,[MODE='r']) shell COMMAND

    os.getpid()

    os.wait()

    os.waitpid(PID,OPTIONS)PID

    os.kill(PID,SIGNAL) kill

    os path

    os.path.dirname(PATH)PATH

    os.path.basename(PATH)PATH

    os.path.split(PATH)

    PATH

    os.path.splitext(PATH) PATH

    os.path.abspath(PATH)".." PATH

    os.path.expanduser(PATH)PATH "~"

    os.path.expandvars(PATH)PATH

    "$VAR"

    os.path.exists(PATH)PATH

    os.path.isabs(PATH) PATH

    os.path.isdir(PATH)/ PATH

    os.path.islink(PATH)PATH

    os.path.ismount(PATH)

    PATH

    os.path.join(P1[,P2[,...]])(

    os.sep

    )

    .. P2

    P1

    os.path.getsize(FILENAME)FILENAME

    os.path.getmtime(FILENAME)1970 FILENAME

    os.path.getatime(FILENAME)1970 FILENAME

    shutil

    shutil.copy(SRC, DEST)( ) DEST SRC

    shutil.copytree(SRC, DEST[,

    SYMS]) SYMS DEST SRC

    shutil.rmtree(PATH)PATH

    time

    time.sleep(SEC) SEC

    time.time()UTC/GMT

    1970

    (time.gmtime(SECtime.localtime(SEC)

    . SEC (year aaaa, month(1-12),day(1-31), hour(0-23),minute(0-59), second(0-59), weekday(0-6, 0 is

    monday), Julian day(1-366), daylight flag(-1,0 or1))

    time.asctime(TM)

    time.strftime(FMT,TM)FMT TM

    time.mktime(TM) TM

    time.strptime(STR[,FMT])localtime FMT STR

    math

    math.pi" "

    math.e

    2.71828183

    euler

    math.fabs(X)

    math.ceil(X)(math.floor(X

    math.fmod(X, Y)X/Y

    math.modf(X) X

    math.ldexp(X, Y)math.frexp(X) 0.3x10+9

    math.asin(X)math.sin(X)

    math.acos(X)math.cos(X)

    (math.tan(X(math.atan(Xmath.atan2(X, Y)

    X/Y

    math.cosh(X)

    math.sinh(X)math.tanh(X)hyperbolic

    math.exp(X)X euler

    math.log10(X)math.log(X)10

    math.sqrt(X)math.pow(X, Y)X Y X

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDF
  • 7/23/2019 Helallinux Com

    10/12

    6.5.8

    class

    class MyClass [(MyClassBase1 , MyClassBase2... )]:

    self . / MyClassBase1 MyClass __member variables .__del ____init ++. *this

    self.X

    MODULE

    import MODULE

    ... .py __ name __

    if __name__ == "__main__":print """Hello, I'm a lib used by other programsdon't runme"""

    #!/usr/bin/python# this is SimpleClass.py

    # OOP and classesclass Simple:# the self arg is just like this (you can't delete it) def __init__(self, str): print "Inside the Simple constructor" self.s = str # Two methods: def show(self): print self.s def showMsg(self, msg): print msg + ':', self.show() # Calling another method# if we are runed as a prog (else then this file is used as module)if __name__ == "__main__": # Create an object: x = Simple("constructor argument")

    x.show() x.showMsg("A message")

    #!/usr/bin/python# Inheritance# search for SimpleClass.py and import itfrom SimpleClass import Simple

    class Simple2(Simple): def __init__(self, str): print "Inside Simple2 constructor" # You must explicitly call

    # the base-class constructor: Simple.__init__(self, str)

    def display(self): self.showMsg("Called from display()") # Overriding a base-class method def show(self): print "Overridden show() method" # Calling a base-class method from inside # the overridden method: Simple.show(self)

    class Different: def show(self): print "Not derived from Simple"

    if __name__ == "__main__": x = Simple2("Simple2 constructor argument") x.display() x.show() x.showMsg("Inside main") def f(obj): obj.show() # One-line definition f(x) f(Different())

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDF
  • 7/23/2019 Helallinux Com

    11/12

    #!/usr/bin/python# i18n with pythonos.environ.get("LC_LOCAL")import gettextgettext.bindtextdomain ("myprog", "/usr/share/locale")gettext.textdomain ("myprog")_=gettext.gettext# any thing to be translated passed to _( )print _("Hello I'll be translated")

    PYTHONPATH="./" gtk- PYTHONPATH : test.py

    import sysimport ossys.path.append(os.path.dirname(sys.argv[0]))# or# sys.environ["PYTHONPATH"]=os.path.dirname(sys.argv[0])

    import gtk

    #!/usr/bin/python# gtk-test.py: simple gtk2 exampleimport gtk

    def hello_cb(button): print "Hello World"

    window.destroy()

    window = gtk.Window(gtk.WINDOW_TOPLEVEL) # create a top level windowwindow.connect("destroy", gtk.mainquit) # quit the event loop on destructionwindow.set_border_width(10) # set padding round child widget

    button = gtk.Button("Hello World")button.connect("clicked", hello_cb) # call hello_cb when clickedwindow.add(button) # add button to windowbutton.show() # show button

    window.show()gtk.main() # enter the main event loop

    : glade GTK 8.3

    #!/usr/bin/pythonimport sysimport gtk

    def quit(*args):gtk.main_quit()def findsum(*args):x=float(entry1.get_text())y=float(entry2.get_text())z=x+yentry3.set_text(str(z))

    win = gtk.Window()table=gtk.Table(4,2)

    label1=gtk.Label('First number: '); entry1=gtk.Entry();label2=gtk.Label('Second number: '); entry2=gtk.Entry();label3=gtk.Label('Summation : '); entry3=gtk.Entry()ok = gtk.Button(stock='gtk-ok');cancel = gtk.Button(stock='gtk-cancel');win.add(table)table.attach(label1,0,1,0,1,gtk.FILL); table.attach(entry1,1,2,0,1,gtk.FILL);table.attach(label2,0,1,1,2,gtk.FILL); table.attach(entry2,1,2,1,2,gtk.FILL);table.attach(label3,0,1,2,3,gtk.FILL); table.attach(entry3,1,2,2,3,gtk.FILL);table.attach( ok ,0,1,3,4); table.attach(cancel,1,2,3,4);

    entry1.set_editable(gtk.TRUE)entry2.set_editable(gtk.TRUE)entry3.set_editable(gtk.FALSE)# another method entry1.set_property('editable',gtk.FALSE)ok.connect('clicked', findsum)

    cancel.connect('clicked', quit)win.connect('destroy', quit)win.show_all()gtk.main()

    glade

    converted by Web2PDFConvert.com

    http://www.web2pdfconvert.com/?ref=PDFhttp://www.web2pdfconvert.com/?ref=PDFhttp://helallinux.com/ojuba-book/ar/gtk.html
  • 7/23/2019 Helallinux Com

    12/12

    import gtkimport gtk.glade

    def some_handler(widget): pass

    xml = gtk.glade.XML('filename.glade')widget = xml.get_widget('widgetname')xml.autoconnect({ 'some_handler': some_handler})gtk.main()

    : CGI python

    #!/usr/bin/python# python and CGIimport cgiprint """Hello world"""

    help

    python

    python

    . (help(gtk.Toolbar import gtk

    www.python.orgwww.python.sf.netwww.starship.python.netwww.vex.net/parnassuswww.zope.comwww.pythonware.comwww.devshed.comwww.mindview.net/Books/TIPythonmembers.nbci.com/alan_gauld/tutor/tutindex.htmaspn.activestate.com/ASPN/Python/cookbookwww.networkcomputing.com/unixworld/tutorial/005/005.htmlwww.vic.auug.org.au/auugvic/av_paper_python.html

    python 6.5

    Copyright 2007, Muayyad Saleh AlSadi

    http://helallinux.com/ojuba-book/ar/php.htmlhttp://helallinux.com/ojuba-book/ar/toc.htmlhttp://helallinux.com/ojuba-book/ar/perl.html