파이션 기본 함수

운영자 | 기사입력 2006/05/08 [08:01]
>
필자의 다른기사 보기 인쇄하기 메일로 보내기 글자 크게 글자 작게
파이션 기본 함수
 
운영자   기사입력  2006/05/08 [08:01]


import time
print time.ctime()
ttime=time.time()
print ttime
ttime2=time.strftime("%y%m%d")
print ttime2
===============================================================
import aaa
class Myclass:
   def set(self):
       print "aaa"
       m=ccc(9)
       print m
   def bbb(self,v):
       v=v+5;
       return v
def ccc(k):
    k=k+10
    return k
c=Myclass()
c.set()
b=c.bbb(5)
print b
d=ccc(20)
print d
zzz=aaa.add(3,4)
print zzz
===========================================================
 #aa.py
def add(a,b):
    return a+b;
 
=====================================================
from urllib import *
class App:
  def __init__(self):
        print 'ok2'
        self.f=self.urllib.urlopen('http://127.0.0.1/aaa.zip')
        file=f.read()
        f=open('aaa.zip','wb')
        f.write(file)
        f.close()     
       
         
    
a=App()
=====================================================
from Tkinter import *
from  urllib  import urlretrieve
import tkMessageBox
import time
class App:
  save_file="t3.txt"
  def __init__(self,master):
        self.frame=Frame(master,width=500,height=500)
        self.frame.pack()
        scrollbar=Scrollbar(master)
        scrollbar.pack(side=RIGHT,fill=Y)
        self.e=StringVar()     
        self.j=Entry(self.frame,textvariable=self.e)
        self.e.set("")
        self.j.pack()
        self.la=StringVar()
        self.label=Label(self.frame,textvariable=self.la);
 self.label.pack()
        ttime2=time.strftime("%y%m%d")    
 
 self.label2=Label(self.frame,text=ttime2)
 self.label2.pack()
 self.la3=StringVar()
        self.label3=Label(self.frame,textvariable=self.la3);
 self.label3.pack()
       
        button=Button(self.frame,text="save",command=self.aaa)
        button1=Button(self.frame,text="quit",command=self.frame.quit)       
        button2=Button(self.frame,text="down",command=self.down)
        button.pack(side=TOP)
        button2.pack()
        button1.pack()
        self.listbox=Listbox(master,yscrollcommand=scrollbar.set)
        try:    
           f=open(self.save_file,"r")
        except IOError:
           f=open(self.save_file,"w")
        else:
           for line in f.readlines():          
              self.listbox.insert(END,line) 
           scrollbar.config(command=self.listbox.yview)
           self.listbox.bind("<Button-1>",self.ok)
           self.listbox.pack()
         
       
  def aaa(self):
        
        self.m_print(self.j.get())
        self.e.set("")
       
  def m_print(self,va):
        print va;
        f=open(self.save_file,"a")
        f.writelines(va+"\n")
 self.frame.update()
  def ok(self,ok):
        #print 'ok'
        item=self.listbox.curselection()
        #item=map(int,item)
        print item
        if tkMessageBox.askyesno("delete","deleted "):
           tkMessageBox.showinfo("selete","Yes")
        else:
           tkMessageBox.showinfo("selecte","NO seleledt")

  def down(self):
        #print 'ok2'
        f=open(self.save_file,"r")
        for line in f.readlines():  
            line.strip()
            line.replace('\n','')
            t=line.split("/")  
            f_name='./'+t[-1].replace('\n','')
            self.la3.set(f_name)
     fname,header=urlretrieve(line,f_name,self.hook)
            #print f_name
       
  def hook(self,blockNumber,blockSize,totalSize):
        print 'downloadong %s of %s '%(blockNumber*blockSize,totalSize)
 f_size=len(str(totalSize))
        if f_size >=7:
              size_m= str(totalSize/1000000)+"M";
 else:
              size_m= str(totalSize)+"M";

        self.la.set('downloadong %s of %s '%(blockNumber*blockSize,size_m));
        self.frame.update() 

root=Tk()
ap=App(root)
root.mainloop()


 
 
트위터 트위터 페이스북 페이스북 카카오톡 카카오톡
기사입력: 2006/05/08 [08:01]  최종편집: ⓒ iwav
 
 
많이 본 기사