7 days into learning PYTHON & looking for some feedback

Hey folks. Title says it all, but... It's been an interesting few days. Never done anything object-oriented before. Previously only had BASH experience. I'm LOVING python. I see so much potential (of course). Can't wait to really get a feel for what's available in the Standard Library.

I have no programmer friends. Actually -- scratch that; I don't even have any *nix friends. So it would be lovely to get some external feedback on my first real python script, so I can nip any bad habits in the bud right now.

Pretty colorized view of code here: https://github.com/ryran/a7crypt/blob/master/a4crypt.py

Thanks for reading!

#!/usr/bin/env python
# a4crypt v0.5.2 last mod 2011/12/17
# Latest version at <http://github.com/ryran/a7crypt>
# Copyright 2011 Ryan Sawhill <ryan@b19.org>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#    General Public License <gnu.org/licenses/gpl.html> for more details.
#------------------------------------------------------------------------------

# TODO: SCRIPT docstring; chop all print() lines down to 79w
# TODO: Implement GPG reading passphrase from fd instead of tempfile with 
# --passphrase-fd or --command-fd (will have to also make data use that method)

# Standard Library stuff only
from os.path import exists
from collections import namedtuple
from getpass import getpass
from tempfile import NamedTemporaryFile
from subprocess import Popen, PIPE, STDOUT


class a4crypt:

    """Provide cmdline wrapper for symmetric {en,de}cryption functions of GPG.
    
    This simply aims to make GPG1/GPG2 symmetric ASCII encryption in terminals
    easier and more fun. (Actually, this was just an excuse for a project in my
    first week of learning python, but hey. ...)
    
    Instantiate this class with color=False if you like spam.
    
    The most important method here is main() -- it will launch an interactive
    prompt and take care of everything for you. That said, you can set the
    proper attribute or two and launch the processing method yourself. ...
    
    And that method would be launch_gpg() which does the actual encryption &
    decryption. To use it directly, first save your input to self.inputdata
    (simple text or file-objects welcome; lists are not), then run:
        launch_gpg(mode, passfile)
    where mode is either e or d and passfile is the path to a file containing
    only your passphrase.
    
    It would of course be simpler and more secure to just let main() do that
    for you, since it would save the passphrase to a tempfile only readable by
    you, and would delete it as soon as the encryption or decryption is done,
    usually only seconds after the file was created. ... But suit yourself.
    
    """

    def __init__(self, color=True):
        """Define vars we need, incl. colors. Check for GPG or GPG2."""
        self.inputdata = ''
        Colors = namedtuple('Colors', 'RST BLD R B G C')
        if color:
            self.c = Colors(
                RST='\033[0m', BLD='\033[0m\033[1m', R='\033[1;31m',
                B='\033[1;34m', G='\033[1;32m', C='\033[0;36m')
        else:
            self.c = Colors('', '', '', '', '', '')
.......
TRIMMED. For the rest, see https://github.com/ryran/a7crypt/blob/master/a4crypt.py

Greetings,
This little post to say ho much I am pleased to see something different, at last a user wishing to share with his peers. I would encourage you to continue this way, unfortunately I don't have time to look at and learn Python (now anyway...) and so I cannot make any comments... perhaps next time in shell (ksh...)?

All the best

Regards vbe. :slight_smile:

You have one now :smiley:

Thanks for the kind words. Despite this being the first post where I wasn't answering someone else's question, a part of me was a little worried I would get misunderstood and flamed for linking. In any case, looks like I need to find some python forums.

Maybe no python geek at the moment... but click on the above python tag and see there are quite some python stuff here, question of patience... Nice clean code you wrote now I took the time to read...

i am also interested in learning a OOP language?? am learning c++ right now .i heard python is a great language and looking forward to learning it as well..thanx for posting :):smiley: