Question about Object Oriented + functions/global vars?
flamesrock
flamesrock at gmail.com
Sun Jun 5 21:40:58 EDT 2005
ok, so to my knowledge, object oriented means splitting something into
the simplest number of parts and going from there. But the question is-
when is it enough?
For example I have the following code:
#def put_file(file_id, delete=False):
# """ Function to put the file on the FTP Server
# """
# print "["+file_id+"] FTP for this file started"
# print "[" + file_id + "] Connecting to machine " + global_addr
# ftp_pool = FTP_pool(file_id,1,40,global_uid,global_pwd)
# print 'in put_file'
# try:
# ftp = ftplib.FTP(global_addr)
# ftp.login(global_uid, global_pwd)
# print ftp.getwelcome() +'\n'
# ftp.cwd(global_ftp_loc)
># ext = os.path.splitext(file_id)[1]
># if ext not in (".sc4", ".snpickle"):
># ftp.storlines("STOR " + file_id, open(file_id))
># else:
># ftp.storbinary("STOR " + file_id, open(file_id, "rb"), 1024)
# ftp.quit()
# ftp_pool.close_all()
# except:
# ftp_pool.close_all()
# print "[" + file_id + "]Unable to access FTP location"
# print "[" + file_id + "]Error:" + str(sys.exc_info()[0]) + " "
+ str(sys.exc_info()[1])
# upload_status[file_id] = "FAILED"
# raise
# else:
# print "[" + file_id + "] FTP for file completed"
# upload_status[file_id] = "SUCCESS"
would the lines with '>#' best be split up into a seperate function,
for example:
#def upload(ftp, file):
# ext = os.path.splitext(file)[1]
# if ext in (".txt", ".htm", ".html"):
# ftp.storlines("STOR " + file, open(file))
# else:
# ftp.storbinary("STOR " + file, open(file, "rb"), 1024)
and then doing the call 'upload(file_id)', or is it a better practice
to leave things the way they were? I'm confused.
Finally, is it considered 'un-object-oriented' in python to have
functions inside a module that are called by objects (ie the upload
function above) and/or use global variables in combination?
-thanks in advance
More information about the Python-list
mailing list