Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103719

common mistakes in this simple program

Path csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail
From Ganesh Pal <ganesh1pal@gmail.com>
Newsgroups comp.lang.python
Subject common mistakes in this simple program
Date Mon, 29 Feb 2016 20:48:57 +0530
Lines 64
Message-ID <mailman.15.1456759145.20602.python-list@python.org> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de X09yG7TgioENjf6zbCQdJAyLlkEa3WAgHUKzhGRz8kAQ==
Return-Path <ganesh1pal@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'sys': 0.05; '__name__': 0.07; 'except:': 0.07; 'main()': 0.07; '%s\\n"': 0.09; 'cmd': 0.09; 'func': 0.09; 'python': 0.10; 'exception': 0.13; 'def': 0.13; 'suggest': 0.15; '"mkdir': 0.16; "'__main__':": 0.16; 'clustering': 0.16; 'e))': 0.16; 'err,': 0.16; 'inputs': 0.16; 'main():': 0.16; 'pdb': 0.16; 'preparing': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:program': 0.16; 'subject:simple': 0.16; 'subprocess': 0.16; 'try:': 0.18; 'to:name :python-list@python.org': 0.20; '%s"': 0.22; 'import': 0.24; 'logging': 0.27; 'skip:# 10': 0.27; 'message-id:@mail.gmail.com': 0.27; '2.6': 0.27; 'ret': 0.29; 'run': 0.33; 'common': 0.33; 'except': 0.34; 'received:google.com': 0.35; 'false': 0.35; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'expect': 0.37; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'improved': 0.63; 'subject:common': 0.84; 'subject:this': 0.85; 'improvement': 0.93; 'mistakes': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to; bh=Qclf84hS9YLEmLkPi+50n+ZmALzZ8jk2fpzAmtu/jpw=; b=EqsTlT7oW8HgUheGDl5AAA02hzUYnKA/jRFCMGUnIKteEZY7kh77Khf01lwIjyNp5F J0b6sza6jbB492fptY5w9RsUZanUvVGrYY6D9hpF+1k6PLXJjaMq6TRtYj6g5APIvstJ YqtQaepquk7SP3kInLGHaNkgBW362ddwsxqlsut6ufoxpJHLa9kgaUUoDttfAYCc2fY2 ZBAyqrHyFOF4dTrC2Ti/5iFKzXzcby/WQfqVhm+RUmLOC+dkCXajWPHWureBxZAoBawV nPi/iB1filQGpLqkiow0YFcKgsAmCM4cLZGxG97dEtTj4/m82gLhZRzkKowtOG3DIFZw rXLw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=Qclf84hS9YLEmLkPi+50n+ZmALzZ8jk2fpzAmtu/jpw=; b=gjZwJfvZ0gVWvi6xHzpFQaFlwPa8nzPajZH+lbOLklresN76NvHNLhHxOapUH/1+Dg 2Awss4uk3Mc+spyxfw7ChwILQli/QdBxd8lMv9E9yZU+r4sPauIGTZuIOzafW0fJqAfD 9tGXjpv8VU8GBM/7v5Gc3TzJ00/f6OcxXlnG6wNXj13I9FFa3b4ahe9JkjkTTXmj8OaI LsMcrQb2JuZ/IG2bipa3ifnaVfPsXsAhMDWCVZWIMlWTy5k1iitdKtjYWqXiEk6GNYSW QYp+1GqgYy8MeWOQTOLkE7FH4UszgRHltCITHqMQqpYvkVRNl0s7FZDPT9GglNZmHQ9J geCA==
X-Gm-Message-State AD7BkJJWLbKvcSa0NJBfYPwXMfju5/eHIW28hWx4y2A3YgpAXDylzKqflSYUYCbDVzFuI9eA696+d7yS+FjVoA==
X-Received by 10.25.169.74 with SMTP id s71mr5857171lfe.135.1456759137212; Mon, 29 Feb 2016 07:18:57 -0800 (PST)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:103719

Show key headers only | View raw


Iam on python 2.6 , need inputs on the common mistakes in this program
, may be you suggest what need to be improved from

1. usage of try- expect
2. Return of True/ False
3. Other improvement

#!/usr/bin/env python

"""
"""

import os
import shlex
import subprocess
import sys
import time
import logging
import run
import pdb


def run_cmd_and_verify(cmd, timeout=1000):
    try:
        pdb.set_trace()
        out, err, ret = run(cmd, timeout=timeout)
        assert ret ==0,"ERROR (ret %d): " \
                " \nout: %s\nerr: %s\n" % (ret, out, err)
    except Exception as e:
        print("Failed to run %s got %s" % (cmd, e))
        return False
    return True

def prep_host():
    """
    Prepare clustering
    """
    for cmd in ["ls -al",
                "touch /tmp/file1",
                "mkdir /tmp/dir1"]:
        try:
            if not run_cmd_and_verify(cmd, timeout=3600):
                return False
        except:
              print("Error: While preparing cluster !!!")
              return False
    print("Preparing Cluster.....Done !!!")
    return True


def main():
    functions = [prep_host]
    for func in functions:
        try:
            func()
        except Exception as e:
            print(e)
            return False
if __name__ == '__main__':
    main()


Regards,
Gpal

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

common mistakes in this simple program Ganesh Pal <ganesh1pal@gmail.com> - 2016-02-29 20:48 +0530

csiph-web