Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Marvel's Wolverine, la recensione: Logan torna protagonista in un'avventura brutale e intensa
Marvel's Wolverine, la recensione: Logan torna protagonista in un'avventura brutale e intensa
Marvel's Wolverine porta Logan in un'avventura inedita, violenta e fortemente narrativa, costruita attorno alla sua natura di combattente e al difficile rapporto con il proprio passato. Insomniac Games punta su combattimenti spettacolari, progressione e personalizzazione, inserendo l'azione in un mondo segnato dalla persecuzione dei mutanti. Un viaggio intenso, che alterna mattanza, esplorazione e momenti sorprendentemente emotivi.
DJI Romo 2: tante novità lo rendono un robot completo
DJI Romo 2: tante novità lo rendono un robot completo
Romo 2 è la seconda generazione di robot lavapavimenti di DJI, un modello che si caratterizza per la precisione nel sistema di navigazione e per il funzionamento particolarmente silenzioso. Con le modifiche introdotte in questa seconda versione, e un posizionamento di prezzo più allineato alla concorrenza, rappresenta una valida alternativa sul mercato delle soluzioni di pulizia domestica
Sony Bravia 9 II: il True RGB alla prova, dove l'LCD sfida l'OLED
Sony Bravia 9 II: il True RGB alla prova, dove l'LCD sfida l'OLED
Il primo Sony con retroilluminazione True RGB alla prova del banco di misura e dei contenuti: luminanza enorme, colori accurati in HDR e un antiriflesso molto efficace. I limiti sono due sole HDMI 2.1 e il blooming fuori asse
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 06-05-2004, 09:03   #1
Luc@s
Senior Member
 
L'Avatar di Luc@s
 
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
[Python]Ottimizzazione

Sto scrivendomi un news reader.
Ora sono arrivato a skarikare i body dei msg e gli heade+subject(poi li fondero assieme).
Pero volevo sapere se il mio code si puo ottimizzare un pochino.
Ecco il code:
Codice:
import os
import sys
import socket
import nntplib
import string

__author__ = "Kleidemos ([email protected])"
__version__ = "$Revision: 0.2 $"
__date__ = "$Date: 2004/05/6 14:00:00 $"
__copyright__ = "Copyright (c) 2004 Luca Francesca"
__license__ = "Python"

kb = 8 * 1024 # a kb unit 

#
# This class elaborate the NewsServerGestion downloaded files
#
class ArticleGestion:
    nws = ''
    article = []
    def Close(self):
         nws.quit()
    # Load into a GROUP_article.txt file the body of the article specified
    # into GROUP.txx file
    # Because this requied many time you should use a modal dialog or any
    # other mode (threads for example) to not block the application GUI
    def ParseGroup(self, server, gname):
        self.nws = nntplib.NNTP(server)
        self.nws.group(gname)
        self.fin = file(gname+"/"+gname+".txt", "r")
        self.fout = file(gname+"/"+gname+"_article.txt", "w")
        while 1:
            self.line = self.fin.readline()
            if not self.line:
                self.fin.close()
                self.fout.close()
                break
            self.str_tmp = string.split(self.line, "\t")
            self.id = self.str_tmp[0]
            for i in self.nws.body(self.id)[3]:
                try:
                    self.fout.write(i+"\n")
                except:
                    print 'Error in write for file',
                    gname+"/"+gname+"_article.txt", '\n'
                #self.fout.write("\n")
            
        self.fin.close()
        self.fout.close()
    # Merge the sebject-header file to the body file and build a group tree
    # to show
    # Because this requied many time you should use a modal dialog or any
    # other mode (threads for example) to not block the application GUI
    # TODO : 100%
    def BuildGroupTree(self, group, farticle, fsubject):
        pass


#
# This class download message from group and save it into a files
#
class NewsServerGestion:
    #
    __i = ''
    #
    __news = ''
    __msg = []
    #
    __group_state = []
    __beg = ''
    __end = ''
    #
    __stats = ''
    #single article
    __single_article = []
    __response = ''
    __number = ''
    __list = ''
    #article range
    __articles_header = []
    articles_list = []
    #article id
    __article_id = []
    def __init__(self, host):
        # Open a server connection
        self.news = nntplib.NNTP(host)
        self.news.getwelcome()
    # Send a article    
    def SendArticle(self, file):
        f = open(file)
        s.post(f)  
    # Download article id & header
    # Because this requied many time you should use a modal dialog or any
    # other mode (threads for example) to not block the application GUI
    def DownloadArticle(self):
        self.fname = self.group_state[4]+"/"+self.group_state[4]+".txt"
        self.articles_list = self.news.xover('subject', self.beg + '-' + self.end, self.fname)
    # Save group info
    def PrintGroupInfo(self, gname):
        if not os.path.exists(gname):
            os.mkdir(gname)
        self.group_state = self.news.group(gname)
        self.stats = self.group_state[0] # set group info
        self.beg = self.group_state[2]   # start message
        self.end = self.group_state[3]   # end message
        f = open(gname+"/"+gname+"_stat.txt", "w")
        try:
            f.write(self.stats)
        except:
            print 'Error in write stat files for', gname, 'group\n'
        f.close()
    def Close(self):
        self.news.quit()
        

if __name__ == "__main__":
   
    print "Test NewsServerGestione on ", sys.getwindowsversion()

    n = NewsServerGestion("news.tin.it")
    
    n.PrintGroupInfo("it.comp.lang.python")
     
    n.DownloadArticle()
    
    n.Close()

    msg = ArticleGestion()
    
    msg.ParseGroup("news.tin.it", "it.comp.lang.python")
    
    msg.Close()

Tnk 1000000000000000000
__________________
Gnu/Linux User

Ultima modifica di Luc@s : 06-05-2004 alle 09:06.
Luc@s è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Marvel's Wolverine, la recensione: Logan torna protagonista in un'avventura brutale e intensa Marvel's Wolverine, la recensione: Logan torna p...
DJI Romo 2: tante novità lo rendono un robot completo DJI Romo 2: tante novità lo rendono un ro...
Sony Bravia 9 II: il True RGB alla prova, dove l'LCD sfida l'OLED Sony Bravia 9 II: il True RGB alla prova, dove l...
Geely EX5, un mese al volante: il SUV elettrico cinese che ci ha sorpreso (quasi) senza riserve Geely EX5, un mese al volante: il SUV elettrico ...
Mova Z70 Ultra Roller Complete: motore potente, rullo di lavaggio e l'IA a guidare Mova Z70 Ultra Roller Complete: motore potente, ...
Perplexity Portable Computer arriva su W...
Se l'IA sostituisse il lavoro i salari r...
Fujitsu Monaka è pronto: 144 core...
Il dispositivo ultra compatto che trasfo...
Bonus colonnine 2026: dal 22 settembre d...
Revolut, una cartella "Italy" ...
Le auto connesse possono vendere i tuoi ...
E se i computer elaborassero le informaz...
NVIDIA non ci sta: "Non lasceremo che l'...
Gli Stati Uniti hanno armi in orbita: ar...
Robot aspirapolvere in offerta su Amazon...
ChatGPT inventa testimoni falsi e un avv...
Find X10 Pro Max di OPPO arriverà...
L'IA scriverà codice migliore del suo st...
Valve apre le prenotazioni di Steam Fram...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 14:12.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v