[Tutor] how do you make this a better code?

Marc Tompkins marc.tompkins at gmail.com
Fri Sep 5 03:29:42 CEST 2008


On Thu, Sep 4, 2008 at 6:00 PM, Roy Khristopher Bayot <roybayot at gmail.com>wrote:


> Correct me if I am wrong but each "import os" statement only exists in each
> method.  Is there a way to only import the os module once and use it in each
> method?
>

Move it to the top of the file, outside of the class definition:

import os
class CamHandle(object):
    def __init__(self):
        w = os.system('gphoto2 --auto-detect > CamHandleLog.txt')
        test = os.system('gphoto2 --capture-image >> CamHandleLog.txt')

    def captureImage(self):
        x = os.system('gphoto2 --capture-image >> CamHandleLog.txt')

    def getAllImages(self):
        y = os.system('gphoto2 --get-all-files >> CamHandleLog.txt')

    def deleteAllImages(self):
        z = os.system('gphoto2 -DR >> CamHandleLog.txt')

I haven't tested your code, but this should work just fine.

-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080904/7d1456b5/attachment.htm>


More information about the Tutor mailing list