omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    clipboard2jpg

    Pythonista
    2
    4
    2342
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • brumm
      brumm last edited by

      My first python script. Please tell me your opinion.
      https://github.com/humberry/clipboard2jpg

      1 Reply Last reply Reply Quote 0
      • brumm
        brumm last edited by

        Another version with camera roll access.
        https://github.com/humberry/camera_roll_resize

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          I am reading "Writing Idomatic Python" to improve my Python code. This book is full of good rules for keeping Python code clean with nice explanations for each rule... http://www.jeffknupp.com/writing-idiomatic-python-ebook

          I saw two rules that related to your script:

          4.1.2 Avoid repeating variable name in compound if statement.

          # instead of:
                  if m == 1:
                          m = '1'
                  elif m == 2:
                          m = 'L'
                  elif m == 3:
                          m = 'RGB'
                  elif m == 4:
                          m = 'RGBA'
                  elif m == 5:
                          m = 'CMYK'
                  elif m == 6:
                          m = 'YCbCr'
                  elif m == 7:
                          m = 'I'
                  else:
                          m = mAlt
                  return m, q
          
          # consider using:
                  menu_options = { 1 : '1',
                                   2 : 'L',
                                   3 : 'RGB',
                                   4 : 'RGBA',
                                   5 : 'CMYK',
                                   6 : 'YCbCr',
                                   7 : 'I' }
                  return menu_options.get(m, mAlt), q
          

          4.1.3 Avoid comparing to True, False, or None.

          # instead of:
          if r == True:
          if (image == None):
          if o == 0:
          
          # consider using:
          if r:
          if not image:
          if not o:
          

          Also... The following line made me gulp because it mixes both new style string formatting (format()) and concatenation (+) with type conversion (str()) in a single line of code. If you are going to make a call to format(), try to take maximum advantage of it.

          # instead of:
          print 'Resolution = ' + str(x) + ' x ' + str(y) + ', quality = {0:.0f}'.format(q*100) + '%, mode = ' + m + ',',
          # consider using:
          print('Resolution = {} x {}, quality = {0:.0f}%, mode = {},'.format(x, y, q*100, m)),
          

          I hope this helps.

          1 Reply Last reply Reply Quote 0
          • brumm
            brumm last edited by

            Thank you very much ccc. Your improvement are looking great.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors