Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Le soluzioni FSP per il 2026: potenza e IA al centro
Le soluzioni FSP per il 2026: potenza e IA al centro
In occasione del Tech Tour 2025 della European Hardware Association abbiamo incontrato a Taiwan FSP, azienda impegnata nella produzione di alimentatori, chassis e soluzioni di raffreddamento tanto per clienti OEM come a proprio marchio. Potenze sempre più elevate negli alimentatori per far fronte alle necessità delle elaborazioni di intelligenza artificiale.
AWS annuncia European Sovereign Cloud, il cloud sovrano per convincere l'Europa
AWS annuncia European Sovereign Cloud, il cloud sovrano per convincere l'Europa
AWS è il principale operatore di servizi cloud al mondo e da tempo parla delle misure che mette in atto per garantire una maggiore sovranità alle organizzazioni europee. L'azienda ha ora lanciato AWS European Sovereign Cloud, una soluzione specificamente progettata per essere separata e distinta dal cloud "normale" e offrire maggiori tutele e garanzie di sovranità
Redmi Note 15 Pro+ 5G: autonomia monstre e display luminoso, ma il prezzo è alto
Redmi Note 15 Pro+ 5G: autonomia monstre e display luminoso, ma il prezzo è alto
Xiaomi ha portato sul mercato internazionale la nuova serie Redmi Note, che rappresenta spesso una delle migliori scelte per chi non vuole spendere molto. Il modello 15 Pro+ punta tutto su una batteria capiente e su un ampio display luminoso, sacrificando qualcosa in termini di potenza bruta e velocità di ricarica
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 06-05-2004, 10: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 10:06.
Luc@s è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Le soluzioni FSP per il 2026: potenza e IA al centro Le soluzioni FSP per il 2026: potenza e IA al ce...
AWS annuncia European Sovereign Cloud, il cloud sovrano per convincere l'Europa AWS annuncia European Sovereign Cloud, il cloud ...
Redmi Note 15 Pro+ 5G: autonomia monstre e display luminoso, ma il prezzo è alto Redmi Note 15 Pro+ 5G: autonomia monstre e displ...
HONOR Magic 8 Pro: ecco il primo TOP del 2026! La recensione HONOR Magic 8 Pro: ecco il primo TOP del 2026! L...
Insta360 Link 2 Pro e 2C Pro: le webcam 4K che ti seguono, anche con gimbal integrata Insta360 Link 2 Pro e 2C Pro: le webcam 4K che t...
Potensic ATOM SE 4K è il miglior ...
JMEV SC01, la supersportiva cinese da 30...
Tesla Model 3 superata per la prima volt...
AMD ha già risolto la crisi della...
La “batteria di Baghdad” funziona davver...
Pannelli solari al contrario? Non propri...
Google Gemini si espande: arrivano le es...
Mercato TV: la leadership di Samsung reg...
L'AI che lavora 100 volte più vel...
LIDAR, battaglia finale: MicroVision met...
Il 2025 è stato l'anno di BYD: +2...
L'IA enterprise entra nella fase decisiv...
Il tiktoker Khaby Lame cede la sua socie...
Apple Pencil Pro scende a 122€ su Amazon...
Ring in forte sconto su Amazon: videocit...
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: 08:07.


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