.. alors je vais essayer Python ... ça à l'air marrant à premiere vu ...
Ceci est un communiqué sans interet aucun d'un momo qui se desespere de programmer bcp mieux en Basic que dans n'importe quel autre langage
QUOTE |
.. alors je vais essayer Python ... ça à l'air marrant à premiere vu ... |
CODE |
from Tkinter import * def Clear_button(): z.delete(1.0,END) def Code_button(): output="" text=z.get(1.0,END) for x in range(len(text)-1): test=str(text[x]) if test>="a" and test<="z": carval=ord(test)+13 if carval>ord("z"): carval=ord("a")+carval%ord("z")-1 output=output+chr(carval) elif test>="A" and test<="Z": carval=ord(test)+13 if carval>ord("Z"): carval=ord("A")+carval%ord("Z")-1 output=output+chr(carval) else: output=output+test z.delete(1.0,END) z.insert(END,output) root = Tk() w = Button(root, text="Code",command=Code_button) w.grid(row=0,column=0) a = Button(root, text="Clear",command=Clear_button) a.grid(row=1,column=0) z=Text(root,font="Times_New_Roman 10",wrap=WORD) z.grid(row=2,column=1) root.mainloop() |
QUOTE |
dwd en cours .. done on verra ça à tête reposée .. m'enfin à mon gout, à côté du java, python est un bonheur de legeretée franchement "a,b=b,a+b" et "elif " sont des idées de génies ... |
CODE |
from Tkinter import * def Clear_bton(): Texte.delete(0,END) Graph.delete(ALL) def Code_bton(): checksum=0 for pos in range(10): Graph.create_line(pos,0,pos,64,fill="white") pos=10 pos=Decode(211214,pos,6) text=Texte.get() for x in range(len(text)): cara=str(text[x]) ctere=-1 for y in range(94): if cara==Jeu_B[y]: ctere=y break pos=Decode(Codes_B[ctere],pos,6) checksum=checksum+((x+1)*ctere) checksum=checksum+104 checksum=checksum%103 print "\nChecksum= %s"%checksum pos=Decode(Codes_B[checksum],pos,6) print "\n", pos=Decode(2331112,pos,7) def Decode(suite,ps,length): variable=0 exposant=6 chiffre=0 for boucle in range(length): essai=str(suite) chiffre=eval(essai[boucle]) if variable==1: variable=0 else: variable=1 print(chiffre), for pixel in range(chiffre): if variable==1: Graph.create_line(ps,0,ps,64) ps=ps+1 else: Graph.create_line(ps,0,ps,64,fill="white") ps=ps+1 return ps Jeu_B=[" ","!",chr(34),"#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[",chr(92),"]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~"] Codes_B=& #91;212222,222122,222221,121223,121322,131222,122213,122312,132212,221213,221312 ,231212,112232,122132,122231,113222,123122,123221,223211,221132,221231,213212,22 3112,312131,311222,321122,321221,312212,322112,322211,212123,212321,232121,11132 3,131123,131321,112313,132113,132311,211313,231113,231311,112133,112331,132131,1 13123,113321,133121,313121,211331,231131,213113,213311,213131,311123,311321,3311 21,312113,312311,332111,314111,221411,431111,111224,111422,121124,121421,141122, 141221,112214,112412,122114,122411,142112,142211,241211,221114,413111,241112,134 111,111242,121142,121241,114212,124112,124211,411212,421112,421211,212141,214121 ,412121,111143,111341,131141,114113,114311,411311,113141,114131,311141,411131,21 1412] root=Tk() Code=Button(root,text="Code",command=Code_bton) Code.grid(row=0,column=0) Clear=Button(root,text="Clear",command=Clear_bton) Clear.grid(row=0,column=1) Texte=Entry(root) Texte.grid(row=1,column=0) Graph=Canvas() Graph.grid(row=2,column=2) root.mainloop() |
QUOTE |
tiens, j'y pense, y a pas moyen de mettre une coloration syntaxique avec les balises codes ? |
CODE |
import re import sys stack = [] for tag in re.findall("<(/?\w+)[^/]*?>", " ".join(open(sys.argv[1]).readlines())): print (tag[0] != '/' and (lambda t: stack.append(t)) or (lambda t: stack.pop() != tag[1:]))(tag) and "\\n%s invalid because of missing <%s> " % (sys.argv[1], tag) or "", |
QUOTE | ||
Y'a des trucs mortels en Python momo, lit mes articles dans Login: :-)))) Tiens, voici un validateur XHTML que j'ai écrit en une ligne :
|
CODE |
#!/usr/bin/env python # NYCTALOPE - 07/30/2002 - 02:33:02 # # Lorsque quelqu'un parle, le bot prend un nombre aléatoirement entre 0 et 1 # Il prend le code ASCII correspondant aux 2 premières décimales de ce nombre # Si ce code apparaît dans le nick en majuscules de l'intervenant, une ligne # des scripts du donjon est envoyée. # # Tout le monde peut dire en public ou en privé : # nyctalope, parle # pour recevoir une citation. # # Le fichier nyctalope.conf permet de configurer le bot. # # GNU-GPL v2, (C)2002 Romain GUY, romain.guy@jext.org import os.path from random import * import re from socket import * import sys ################################################################################ ########## # CONSTANTES - Définies dans le fichier nyctalope.conf # Ce sont les valeurs par défaut si le fichier nyctalope.conf est introuvable. ################################################################################ ########## BOT_CHANS = '#pcteam,#progworld' # canaux (séparés par des virgules) BOT_HOST = 'ircnet.kaptech.fr' # serveur BOT_PORT = 6667 # port sur le serveur IRC BOT_IDENT = 'nyctalope' # nick ET ident du bot OP = '.?gfx@.*\.ppp\.tiscali\.fr' # masque de l'administrateur (c'est une regex) IDENT_PORT = 113 # port ident (local) ################################################################################ ########## # CODE SOURCE ################################################################################ ########## DEBUG = 0 # mode debug sourceFiles = [] # EMISSION D'UNE CITATION def quote(source): randomizer = Random() file = sourceFiles[randomizer.randrange(1, len(sourceFiles))] if file[-1] == '\n': file = file[:-1] quotes = open(file) lines = quotes.readlines() line = '' quotes.close() while len(line) == 0: line = lines[randomizer.randrange(1, len(lines))].strip() if DEBUG: print line bot.send('NOTICE ' + source + ' :' + line + '\r\n') # CONFIGURATION print "Reading configuration..." if os.path.exists('nyctalope.conf'): conf = open('nyctalope.conf') lines = conf.readlines() conf.close() for line in lines: match = re.search('^([^=]*)=(.*)$', line) if match is not None: key, value = match.groups(2) if key == 'BOT_CHANS': BOT_CHANS = value elif key == 'BOT_HOST' : BOT_HOST = value elif key == 'BOT_PORT' : BOT_PORT = int(value) elif key == 'BOT_IDENT': BOT_IDENT = value elif key == 'OP' : OP = '(\+.)?' + value.replace('.', '\.').replace('*', '.*') # CREATION DE LA LISTE DES FICHIERS print "Gathering data..." naheulbeuk = re.compile('\?|/?Pen of Chaos_Le Donjon de Naheulbeuk \d\d.*.txt$') for file in os.listdir('.'): if naheulbeuk.search(file): sourceFiles.append(file) # SOCKETS print "Creating sockets..." ident, bot = socket(AF_INET, SOCK_STREAM), socket(AF_INET, SOCK_STREAM) # SERVEUR IDENT print "Running ident server on port", IDENT_PORT, "..." try: ident.bind(('', IDENT_PORT)) ident.listen(1) bot.connect((BOT_HOST, BOT_PORT)) irc, irchost = ident.accept() print "Got ident request, answering..." irc.send(re.search('(\d+)', irc.recv(1024)).group(1) + ", " + str(BOT_PORT) + ' : USERID : UNIX : ' + BOT_IDENT) irc.close() ident.close() except: print "Ident server already running on port", IDENT_PORT, "..." # CONNEXION DU BOT print "Connecting bot..." try: bot.send('NICK ' + BOT_IDENT + '\r\n') bot.send('USER ' + BOT_IDENT + ' ' + gethostname() + ' ' + BOT_HOST + ' :' + BOT_IDENT + '\r\n') while (bot.recv(1024).find('376 ' + BOT_IDENT) == -1): pass bot.send('JOIN ' + BOT_CHANS + '\r\n') except: print "Could not connect, try changing bot nick..." sys.exit(1) # BOUCLE PRINCIPALE while 1: # RECEPTION D'UNE LIGNE DU SERVEUR match = re.search('(?m)^PING.+|:([^!]+)!([^\s]+)\s+(\w+)\s+(#?\w+)?\s*([^:]+)?:?([^\r]*)', bot.recv(1024)) if match is not None: nick, id, command, source, arg, text = match.groups(5) # PING PONG if match.group(0).find('PING') == 0: bot.send('PONG ' + BOT_IDENT + '\r\n') else: # COMMANDES PUBLIQUES if command == 'PRIVMSG': # COMMANDES DE L'OP if re.search(OP, id) is not None: match = re.search('^' + BOT_IDENT + ', (.*)$', text) if match is not None: command = match.group(1) if command == 'quit': bot.send("QUIT :Je le savais bien que t'étais une salope !!\r\n") bot.close() break # COMMANDES TIERS match = re.search('^' + BOT_IDENT + ', (parle)\s?(.*)$', text) if match is not None: command, arguments = match.groups(2) # ORDRE DE PARLER if command == 'parle': quote(('#' in source and source or nick)) print "I've been forced to talk by", nick, "..." # CITATION ALEATOIRE elif chr(int(re.search('0\.(\d\d)', str(Random().random())).group(1))) in nick.upper(): quote(('#' in source and source or nick)) print "I've randomly quoted on", nick, "talk..." # REJOINDRE LES CHANS elif command == 'PART': if text == BOT_IDENT and nick == BOT_IDENT: bot.send('JOIN ' + source + '\r\n') print "Rejoining chan", source, "..." # REJOINDRE APRES UN KICK elif command == 'KICK': if arg.strip() == BOT_IDENT: bot.send('JOIN ' + source + '\r\n') print "Kicked, rejoining chan", source, "..." # end of nyctalope.py |
CODE |
from Tkinter import * def Dwords(files): temp1=ord(files.read(1))*256**0 temp2=ord(files.read(1))*256**1 temp3=ord(files.read(1))*256**2 temp4=ord(files.read(1))*256**3 return temp1+temp2+temp3+temp4 def Words(files): temp3=ord(files.read(1))*256**0 temp4=ord(files.read(1))*256**1 return temp3+temp4 def Read_Header_Bmp(bmpfile): text=bmpfile.read(2) print bmpfile print "========BMP-Header Information========" if text=="BM": print "first Dword 'BM' : ok" else: print text bfSize=Dwords(bmpfile) print "File size in Dwords:", bfSize reserv1=Words(bmpfile) print "Must be zero:", if reserv1==0: print "ok" else: print "error" reserv2=Words(bmpfile) print "Must be zero:", if reserv2==0: print "ok" else: print "error" offbits=Dwords(bmpfile) print "Image data offset:",offbits info=Words(bmpfile) print "Info header=",info,"bytes" #Why Dwords are differents here ??? # it seems to be a .read error ... ??? temp1=ord(bmpfile.read(1))*256**2 temp2=ord(bmpfile.read(1))*256**3 temp3=ord(bmpfile.read(1))*256**0 temp4=ord(bmpfile.read(1))*256**1 width=temp1+temp2+temp3+temp4 print "Width=",width temp1=ord(bmpfile.read(1))*256**2 temp2=ord(bmpfile.read(1))*256**3 temp3=ord(bmpfile.read(1))*256**0 temp4=ord(bmpfile.read(1))*256**1 height=temp1+temp2+temp3+temp4 print "Height=",height temp1=ord(bmpfile.read(1))*256**2 temp2=ord(bmpfile.read(1))*256**3 temp3=ord(bmpfile.read(1))*256**0 temp4=ord(bmpfile.read(1))*256**1 planes=temp1+temp2+temp3+temp4 print "Must be '1':", if planes==1: print "ok" else: print "error" bitcount=Words(bmpfile) print "Bits per pixel:",bitcount compression=Dwords(bmpfile) print "Compression type:",compression sizeimage=Dwords(bmpfile) print "Image size in Bytes:",sizeimage xpxelpermeter=Dwords(bmpfile) print "Pixels per meter (X):",xpxelpermeter ypxelpermeter=Dwords(bmpfile) print "Pixels per meter (Y):",ypxelpermeter colorused=Dwords(bmpfile) if colorused==0: print "All colors used" else: print colorused,"colors used" colorimportant=Dwords(bmpfile) print colorimportant,"important color(s)" print "============End of header ============" return [width,height,bitcount,offbits,sizeimage] def Bmp_read_24(offbits,width,height,bmpfile,size): data=[] print bmpfile.tell() bmpfile.seek(0) bmpfile.seek(offbits) if bmpfile.tell()<>offbits: print "file error" for count in range(0,size,3): blue=ord(bmpfile.read(1)) green=ord(bmpfile.read(1)) red=ord(bmpfile.read(1)) data.append([red,green,blue]) return data # file=open("C:/Documents and Settings/momo1/Bureau/Python/Test.dat","rb") file=open("Test.dat","rb") bmpinfo=Read_Header_Bmp(file) if bmpinfo[2]==24: print "launch 24 bits decoding routine" bmpdata=Bmp_read_24(bmpinfo[3],bmpinfo[0],bmpinfo[1],file,bmpinfo[4]) file.close() print"file closed" root=Tk() bitmap=Canvas(width=bmpinfo[0],height=bmpinfo[1]) bitmap.pack() root.title("just a dumb test") counter=0 # need to find a less memory and cpu hungry method # a "raw" bitmap would be perfect for count1 in range(bmpinfo[1],0,-1): for count in range(bmpinfo[0]+1): color="#%02x%02x%02x" % (bmpdata[counter][0],bmpdata[counter][1],bmpdata[counter][2]) counter+=1 bitmap.create_line(count,count1,count,count1+1,fill=color) root.mainloop() |