How do I check all variables returned buy the functions exists

2017-09-15 Thread Ganesh Pal
I have a function that return's x variables How do I check if all the the values returned are not None/False/0/'' Here is the same program to demonstrate this , but I felt this can be better any suggestions ? # vi file.py import random import string def return_x_values(): " returns x

How to ingore "AttributeError: exception

2017-09-22 Thread Ganesh Pal
I have two possible values for Z_block in the block code i.e disk_object.data.data.di_data[0] or block.data.data.di_data.data[0][0] def get_block(): ''' Get Z block '' if block.data.data.di_data.data[0][0] is not None: Z_block = block.data.data.di_data.data[0][0] else:

Re: How to ingore "AttributeError: exception

2017-09-22 Thread Ganesh Pal
> > > is a perfectly good pattern to use. > Thanks looks nice :) > > > > > > > > I am a Linux user on Python 2.7 > > Have you considered moving to Python 3? > Not yet , but Is there something that I need to consider in the current context? Regards, Ganesh -- https://mail.python.org/mailma

How to join elements at the beginning and end of the list

2017-10-31 Thread Ganesh Pal
How to join each elements with a delimiter at (1) beginning and end of the list and (2) connecting all elements of the list Example : >>> value_list = [1, 2, 3, 4, 56, 's'] I want this to be converted in this from '||1||2||3||4||56||s||' Here is my solution >>> values = '||' + '||'.join(ma

Helloworld with Python C extension

2016-08-29 Thread Ganesh Pal
Hello Team , I need you input on the below hello world program. I a m trying to add a python binding which will return the character for the given index . I am on Python 2.7 and linux Example : >> string ='helloworld' >>dda_hello(5) >> 'w' /* + * Hello world example for python bindings +

Re: Helloworld with Python C extension

2016-08-29 Thread Ganesh Pal
> > > > Py_BuildValue with an "s" expects a C string - that is, a pointer to > char, not just a single character. You'd need to do something like > this: > > char buf[2] = {char1, 0}; > return Py_BuildValue("s", buf); > > ChrisA Thanks Chris for the clue's it worked, I was just wondering ho

C Python extension to export an Function

2016-08-31 Thread Ganesh Pal
Hi Team, Iam on python 2.7 and Linux. Iam pretty new to C Python extension , I was able to export few simple modules to python and it look like the cool thing to do , but Iam stuck for with a problem now , Iam not able to figure out how to export fun_addr_from_addr() to Python. I would need s

Re: C Python extension to export an Function

2016-09-01 Thread Ganesh Pal
On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote: > Ganesh Pal writes: > > > Iam pretty new to C Python extension , I was able to export few simple > > modules to python and it look like the cool thing to do ... > > Maybe, it is a good idea to have a look at "cython

Re: C Python extension to export an Function

2016-09-01 Thread Ganesh Pal
C code. I want to use C/Python API <https://docs.python.org/2/c-api/> On Thu, Sep 1, 2016 at 6:32 PM, Stefan Behnel wrote: > Ganesh Pal schrieb am 01.09.2016 um 14:30: > > On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote: > >> Ganesh Pal writes: > >>> Iam pretty

list or dictionary

2016-09-20 Thread Ganesh Pal
I am on python 2.7 and Linux I have the stdout in the below form , I need to write a function to get hostname for the given id. Example: >>> stdout 'hostname-1 is array with id 1\nhostname-2 is array with id 2\nhostname-3 is array with id 3\n' def get_hostname(id) return id what's a

Re: list or dictionary

2016-09-21 Thread Ganesh Pal
print mo.group(1) ... RX-145-1 is array id 1 (.*) is array with id 3 None RX-145-2 is array id 2 (.*) is array with id 3 None RX-145-3 is array id 3 (.*) is array with id 3 None --- Looks like Iam

Re: list or dictionary

2016-09-21 Thread Ganesh Pal
Thanks , and it has to be re.match() On Thu, Sep 22, 2016 at 12:18 AM, MRAB wrote: > On 2016-09-21 19:35, Ganesh Pal wrote: > >> Thanks Steve for the clues , quickly tried out # Version 1 doesn't seen >> to work. >> >> >> for line in hostname: >&g

How to you convert list of tuples to string

2016-11-22 Thread Ganesh Pal
912 and >>> c1 = c1[0:-5] + ':8912' >>> c1 '3,5,340058112:8912' >>> Any better suggestion to improve this piece of code and make it look more / pythonic Regards, Ganesh Pal -- https://mail.python.org/mailman/listinfo/python-list

correct way to catch exception with Python 'with' statement

2016-11-27 Thread Ganesh Pal
Dear Python friends, Any suggestion on how to add exception and make the below program look better , I am using Python 2.7 and Linux def create_files_append(): """ """ try: os.makedir

Simple Python equivalent for the shell command

2016-11-28 Thread Ganesh Pal
I was trying to write a function that will return me the unique number associated with each employee id.The command has the output in the below pattern Linux-Box-1# employee_details ls List of names: 100910bd9 s7018 100d60003 s7019 110610bd3 s7020 100d60002 s7021 Linux-Box-1# employee_details

Re: correct way to catch exception with Python 'with' statement

2016-11-28 Thread Ganesh Pal
On Mon, Nov 28, 2016 at 1:16 PM, Steven D'Aprano < [email protected]> wrote: > > > There is no need to return True. The function either succeeds, or it > raises an > exception, so there is no need to return any value at all. > > I returned True here ,because based on the result

Re: Simple Python equivalent for the shell command

2016-11-28 Thread Ganesh Pal
turn False return emp_unum PS : [Edited the above code with else condition] Regards, Ganesh On Mon, Nov 28, 2016 at 8:38 PM, Ganesh Pal wrote: > > > I was trying to write a function that will return me the unique number > associated with each employee id.The command has the

Re: correct way to catch exception with Python 'with' statement

2016-11-28 Thread Ganesh Pal
[email protected]> wrote: > On Tuesday 29 November 2016 02:18, Ganesh Pal wrote: > > > On Mon, Nov 28, 2016 at 1:16 PM, Steven D'Aprano < > > [email protected]> wrote: > > > >> > >> > >> There is no need to return Tr

Re: Simple code and suggestion

2016-11-30 Thread Ganesh Pal
On Wed, Nov 30, 2016 at 7:33 PM, Dennis Lee Bieber wrote: > On Wed, 30 Nov 2016 18:56:21 +0530, g thakuri > declaimed > the following: > > >Dear Python friends, > > > >I have a simple question , need your suggestion the same > > > >I would want to avoid using multiple split in the below code , w

how do I retry a command only for a specific exception / error

2018-03-15 Thread Ganesh Pal
-g groupname] [-d] [-m] [-u] [-v] Failed, Retrying in 4 seconds... Case 3: Assuming my command threw an exception say OSError , how do I retry a command only for a specific exception / error I am on Python 2.7 and Linux Regards, Ganesh Pal -- https://mail.python.org/mailman/listinfo/python-list

Re: how do I retry a command only for a specific exception / error

2018-03-19 Thread Ganesh Pal
On Fri, Mar 16, 2018 at 11:21 AM, Steven D'Aprano < [email protected]> wrote: > On Fri, 16 Mar 2018 11:04:22 +0530, Ganesh Pal wrote: > > > All that I am trying to do here is write a generic function that will > > re-retry > > the command

Re: how do I retry a command only for a specific exception / error

2018-03-21 Thread Ganesh Pal
Please ensure quoted text is quoted, and new text you write is unquoted. > That way you are more likely to get useful > Sorry , Steve I didn't realize but thanks for pointing out I will take care I was on a mobile phone and messed the quoted text >Something like this should do it. It gives up imm

String Formatting with new .format()

2018-03-26 Thread Ganesh Pal
Hi Team, Just a quick suggestion, on string formatting with .format() which of the below is better , given both give the same result . >>> attempts = 1 >>> msg2 = "Hello" >>> print "Retry attempt:{0} for error:{1}".format(attempts,msg2) Retry attempt:1 for error:Hello OR >>> attempts = 1 >>> ms

Re: String Formatting with new .format()

2018-03-27 Thread Ganesh Pal
> > > Or maybe they're not giving the same result. I'm a little confused here. > > Thanks Chris, for the reply they appear to give the same result . -- https://mail.python.org/mailman/listinfo/python-list

Pep8 for long pattern

2018-03-27 Thread Ganesh Pal
Hello Python friends, How do I split the below regex , so that it fits within the character limit of 79 words pattern = [ r'(?P([0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+::HEAD))', r'(?P(owner:\s+[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+:[0-9a-fA-F]+::HEAD))',

Re: String Formatting with new .format()

2018-03-28 Thread Ganesh Pal
> > Or maybe they're not giving the same result. I'm a little confused here. > My Bad and Apologies , I should be fined for pasting wrong question. Actually I wanted to know if its ok to use just empty {} with .format() or use {} with values i.e {0} {1} both will give the same results anyway

Converting list of tuple to list

2018-03-29 Thread Ganesh Pal
Hello Team, I have a list of tuple say [(1, 2, 1412734464L, 280), (2, 5, 1582956032L, 351), (3, 4, 969216L, 425)] . I need to convert the above as ['1,2,1412734464:280', '2,5,1582956032:351', '3,4,969216:425'] Here is my Solution , Any suggestion or optimizations are welcome . Solution

Print Failure or success based on the value of the standalone tool

2018-05-10 Thread Ganesh Pal
I have to test a standalone tool from a python script and I am using os.system() to run the tool . I need to take decision based on the return value of the standalone tool . But since os.system merely throws the output value to STDOUT & returns the exit status (0 => no error) of the shell , how c

Re: Print Failure or success based on the value of the standalone tool

2018-05-10 Thread Ganesh Pal
On Thu, May 10, 2018, 22:31 Rob Gaddi > > > By not using os.system, it's been superseded for reasons exactly like > yours. https://docs.python.org/3/library/subprocess.html is your friend. > Can someone please help me understand this better for me with a program . Will the returncode of subproc

Regex to extract multiple fields in the same line

2018-06-13 Thread Ganesh Pal
Hi Team, I wanted to parse a file and extract few feilds that are present after "=" in a text file . Example , form the below line I need to extract the values present after --struct =, --loc=, --size= and --log_file= Sample input line = '06/12/2018 11:13:23 AM python toolname.py --struct=d

Re: Regex to extract multiple fields in the same line

2018-06-13 Thread Ganesh Pal
On Wed, Jun 13, 2018 at 5:59 PM, Rhodri James wrote: > On 13/06/18 09:08, Ganesh Pal wrote: > >> Hi Team, >> >> I wanted to parse a file and extract few feilds that are present after "=" >> in a text file . >> >> >> Example , form

Re: Regex to extract multiple fields in the same line

2018-06-15 Thread Ganesh Pal
> {'struct': 'data_block', 'log_file': '/var/1000111/test18.log', 'loc': > '0', 'size': '8'} > > MARB, as usual the solution you you look nice, Thanks for the excellent solutions >>> regex = re.compile (r"--(struct|loc|size|mirror|l og_file)\s*=\s*([^\s]+)") >>> regex.findall (line) [('struct

For specific keys , extract non empty values in a dictionary

2018-06-16 Thread Ganesh Pal
*How do I check few specific/selected keys in a dictionary and extract their values if they are not empty* *Example : Extract the values for key "one","three","seven" and "nine” if they are not empty* *Input :* *o_num = {'one': 1,* * 'three': 3,* * 'bar': None,* *

Re: For specific keys , extract non empty values in a dictionary

2018-06-17 Thread Ganesh Pal
k] is not None} TypeError: unsupported operand type(s) for &: 'set' and 'list' Example : >>>print {k: o_num[k] for k in wanted and o_num.keys() if o_num[k] is not None} {'nine': 9, 'five': 5, 'three': 3, 'one': 1} On

write the values of an ordered dictionary into a file

2018-06-21 Thread Ganesh Pal
Hi Team I need to write the values of an ordered dictionary into a file . All values should be in a single row with a header list *Example:* *student = [("NAME", "John"),* * ("AGE", 28),* * ("SCORE", 13),* * ("YEAR", 2018),* * ("FEE", 250)]* *st

try except inside a with open

2018-07-20 Thread Ganesh Pal
Dear python Friends, I need a quick suggestion on the below code. def modify_various_line(f): """ Try modifiying various line """ try: f.write('0123456789abcdef') f.seek(5) # Go to the 6th byte in the file print f.read(1) f.seek(-3, 2) # Go to the 3rd

Re: try except inside a with open

2018-07-21 Thread Ganesh Pal
> > > > (1) Since this function always returns True (if it returns at all), what > is the point? There's no point checking the return result, since it's > always true, so why bother returning anything? > > If I don't return anything from a function it returns None. But would it be better if for

Better way / regex to extract values form a dictionary

2018-07-21 Thread Ganesh Pal
I have one of the dictionary values in the below format '/usr/local/ABCD/EDF/ASASAS/GTH/HELLO/MELLO/test04_Failures.log' '/usr/local/ABCD/EDF/GTH/HEL/OOLO/MELLO/test02_Failures.log' '/usr/local/ABCD/EDF/GTH/BEL/LO/MELLO/test03_Failures.log' I need to extract the file name in the path example, say

Re: Better way / regex to extract values form a dictionary

2018-07-21 Thread Ganesh Pal
> The dictionary is irrelevant to your question. It doesn't matter whether > the path came from a dict, a list, read directly from stdin, an > environment variable, extracted from a CSV file, or plucked directly from > outer space by the programmer. The process remains the same regardless of > wher

how to optimize the below code with a helper function

2016-04-04 Thread Ganesh Pal
Hi Team, Iam on python 2.7.10 and Linux. I have a python function where the similar kind of pattern repeating 100 of times Sample code snippet: test01_log = os.path.join(LOG_DIR, "test01.log") cls.get_baddr['test01'] = failure.run_tool( test01_log, object="inode", offset="1

sys.exit(1) vs raise SystemExit vs raise

2016-04-12 Thread Ganesh Pal
I m on python 2.7 and Linux , I have a simple code need suggestion if I I could replace sys.exit(1) with raise SystemExit . ==Actual code== def main(): try: create_logdir() create_dataset() unittest.main() except Exception as e: logging.exception(e)

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-12 Thread Ganesh Pal
> > > No; raise SystemExit is equivalent to sys.exit(0); you would need raise > SystemExit(1) to return 1. > Thanks will replace SystemExit with SystemExit(1) . > Why do you want to do this, though? What do you think you gain from it? > Iam trying to have a single exit point for many function

Skipping test using unittest SkipTest and exit status

2016-05-13 Thread Ganesh Pal
Hi Team, Iam on python 2.7 and Linux . I need inputs on the below program , Iam skipping the unittest from setUpClass in following way # raise unittest.SkipTest(message) The test are getting skipped but I have two problem . (1) This script is in turn read by other scripts which consid

Re: Skipping test using unittest SkipTest and exit status

2016-05-14 Thread Ganesh Pal
> > > Hi Team, > > > > Iam on python 2.7 and Linux . I need inputs on the below program , > > "I am" is two words, not one. I hope you wouldn't write "Youare" > or "Heis" :-) Whenever you write "Iam", I read it as the name "Ian", which > is very distracting. > > I am lazy fellow and you are sm

re.search - Pattern matching review

2016-05-28 Thread Ganesh Pal
Dear Python friends, I am on Python 2.7 and Linux . I am trying to extract the address "1,5,147456:8192" from the below stdout using re.search (Pdb) stdout 'linux-host-machine-1: Block Address for 1,5,27320320:8192 (block 1,5,147456:8192) --\nlinux-host-machine-1: magic 0xdeaff2fe mark_c

re.search - Pattern matching review ( Apologies re sending)

2016-05-28 Thread Ganesh Pal
Dear Python friends, I am on Python 2.7 and Linux . I am trying to extract the address "1,5,147456:8192" from the below stdout using re.search (Pdb) stdout 'linux-host-machine-1: Block Address for 1,5,27320320:8192 (block 1,5,147456:8192) --\nlinux-host-machine-1: magic 0xdeaff2fe mark_c

Re: re.search - Pattern matching review ( Apologies re sending)

2016-05-28 Thread Ganesh Pal
> Perhaps: > map(int, re.search(search_pat, stdout).groups()) > > > Thanks Albert map saved me many lines of code but map returns a list I will have to convert the list to string again Below is how Iam planning to teh conversion >>> block = map(int, re.search(search_pat, stdout).groups()) >>> p

Re: re.search - Pattern matching review ( Apologies re sending)

2016-05-29 Thread Ganesh Pal
;, '1375772672', '8192') (Pdb) matched.group() 'Block Address for 1,0,1376034816:8192 (block *1,0,1375772672:8192*' Regards, Ganesh On Sun, May 29, 2016 at 11:53 AM, Ganesh Pal wrote: > > > >> Perhaps: >> map(int, re.search(search_pa

python parsing suggestion

2016-05-30 Thread Ganesh Pal
Hi , Trying to extract the '1,1,114688:8192' pattern form the below output. pdb>stdout: '3aae5d0-1: Parent Block for 1,1,19169280:8192 (block 1,1,114688:8192) --\n3aae5d0-1: magic 0xdeaff2fe mark_cookie 0x\ngpal-3aae5d0-1: super.status 3super.cookie

Re: re.search - Pattern matching review

2016-05-30 Thread Ganesh Pal
On Sun, May 29, 2016 at 10:32 PM, Matt Wheeler wrote: > > > This doesn't seem to exactly match your code below, i.e. your code is > attempting to construct a tuple from groups 1 through 4. To meet this > specification I could just `return re.search('(?<=\(block > )[^(]*(?=\))', stdout).group()` >

Re: re.search - Pattern matching review

2016-06-01 Thread Ganesh Pal
Thanks works fine : ) -- https://mail.python.org/mailman/listinfo/python-list

one command on backslash and space for review

2016-07-10 Thread Ganesh Pal
Hello Team, I am on python 2.7 and Linux , I want to form the below sample command so that I could run it on the shell. Command is --> run_parallel -za1 -s 'daemon -cf xyz; sleep 1' Here is how I formed the command and it seems to look fine and work fine , but I think it could still be better

Re: one command on backslash and space for review

2016-07-10 Thread Ganesh Pal
On Jul 10, 2016 11:14 PM, "Ian Kelly" wrote: > They're correct, but using them before single quotes in a string > delimited by double quotes is unnecessary. Thanks . > > 3. Iam running sleep command on the cluster i.e , how could I make it > > look Python or its fine to have sleep ? > > I don't

Re: one command on backslash and space for review

2016-07-10 Thread Ganesh Pal
> > > > cmd = "run_parallel -za" + str(number) + \ > > ... " -s" + " \'daemon -cf xyz; sleep 1\'" > > cmd = "run_parallel -za{} -s 'daemon -cf xyz; sleep 1'".format(number) > > How will I format number to strings using .format ?? Example >>> str(num) '100' >>> cmd = "run_parallel -z

use import *

2016-08-01 Thread Ganesh Pal
Hi Team , I am a Linux user on python 2,6 . I have a very simple question I was going the zen of python by Tim peters and found an example that demonstrates Explicit is better than implicit """Load the cat, dog, and mouse models so we can edit instances of them.""" def load(): from menageri

Intitalize values for a class

2018-11-23 Thread Ganesh Pal
Hello team, I am a python 2.7 user on Linux. I will need feedback on the below program as I'm new to oops . #!/usr/bin/python class System(object): '''Doc - Inside Class ''' def __init__(self, params=None): if params is None: self.params = {'id': '1',

Re: initialize the values of the class

2018-11-23 Thread Ganesh Pal
Sorry for reposting, typo in the subject line ! On Fri, Nov 23, 2018, 19:11 Ganesh Pal Hello team, > > I am a python 2.7 user on Linux. I will need feedback on the below program > as I'm new to oops . > > #!/usr/bin/python > > > class System(object): > >

Re: Intitalize values for a class

2018-11-23 Thread Ganesh Pal
On Fri, Nov 23, 2018, 19:30 Bob Gailer What kind of feedback do you want? > Wanted to know if there is any problem in the code and if you can review it :-) > -- https://mail.python.org/mailman/listinfo/python-list

How to remove "" from starting of a string if provided by the user

2020-08-10 Thread Ganesh Pal
How to remove " from the starting and ending of a string , before comparison . Here is an example and my solution wtih eval ( I am advised not to use this one) , please suggest an alternative . I am on linux and python 2.7 g1@X1:/tmp$ cat file2.py #!/usr/bin/python # Case 1 - server2 file is "'/f

Re: How to remove "" from starting of a string if provided by the user

2020-08-10 Thread Ganesh Pal
].startswith("\"") and stat['server2'].endswith("\""): ...stat['server2'] = ast.literal_eval(stat['server2']) ... >>> I tried startswith() and endswith(), doesn't seem to work ?. Is there a simpler way ? Regards,

how to make the below code look better

2015-12-02 Thread Ganesh Pal
Hello team, I need suggestion to improve the below code , Iam on Linux and python 2.7 if not os.path.ismount("/tmp"): sys.exit("/tmp not mounted.") else: if create_dataset() and check_permission(): try: run_full_back_up() run_partial_back_up() except

Re: how to make the below code look better

2015-12-02 Thread Ganesh Pal
On Wed, Dec 2, 2015 at 6:00 PM, Chris Angelico wrote: > If both the functions return true values, yes. You have an indentation > error there, but I'm assuming you meant to have the try/except > indented further. > Correct I had meant to have try/except indented further. >> 2. Can I have a if sta

storing test logs under /var/log/

2015-12-02 Thread Ganesh Pal
Hi Team , I would need few tips from your past experiences on how to store the test logs My requirement is to capture log under /var/log/ directory every time the test is run . The test will create one small log files which are around 1KB in size . Here is how I plan to approach this ,

Re: storing test logs under /var/log/

2015-12-08 Thread Ganesh Pal
> Finally. sys.exit accepts an integer, not a string. > Most of code uses sys.exit("some error message") , I did notice that the error message is not displayed by sys .exit("some error message") , do u mean that using string is not advisable with sys.exit ? How to I display error messages wi

Re: storing test logs under /var/log/

2015-12-08 Thread Ganesh Pal
> Wrong question; if you want to use sys.exit() in a way similar to C display > the error message first and invoke sys.exit() afterwards with a numerical > argument. > > -- oh ok , got it thanks :) -- https://mail.python.org/mailman/listinfo/python-list

python unit test frame work

2015-12-10 Thread Ganesh Pal
Hello Team, Iam on python 2.7 and linux. Iam trying to understand the python unit test frame work and also trying to fix the below code , any help in this regard would be appreciated ? # Sample code starts here inject_failure = {} report = "" ClassIsSetup = False ClassCleanup = F

Re: python unit test frame work

2015-12-10 Thread Ganesh Pal
+python list . sorry I accidentally did a reply to Peter. On Dec 11, 2015 3:57 AM, "Ganesh Pal" wrote: > > > > Drop the habit to sprinkle sys.exit() all over the place. A well-behaved > > application has one exit point, at the end of the main module. > I was u

Re: python unit test frame work

2015-12-12 Thread Ganesh Pal
On Thu, Dec 10, 2015 at 9:20 PM, Peter Otten <[email protected]> wrote: > Ganesh Pal wrote: > > I recommend that you reread the unittest documentation. > > setUpClass() should be a class method, and if it succeeds you can release > the ressources it required in the cor

Calling a list of functions

2015-12-13 Thread Ganesh Pal
Hi Team, Iam on linux and python 2.7 . I have a bunch of functions which I have run sequentially . I have put them in a list and Iam calling the functions in the list as shown below , this works fine for me , please share your opinion/views on the same Sample code : def print1(): print "

does the order in which the modules are placed in a file matters ?

2015-12-16 Thread Ganesh Pal
Iam on python 2.7 and linux .I need to know if we need to place the modules in a particular or it doesn't matter at all order while writing the program For Example import os import shlex import subprocess import time import sys import logging import plaftform.cluster from util import run def

How to ignore error with anon-zero exit status

2015-12-20 Thread Ganesh Pal
def run_scanner(): """ Mount /filesystems and run scanner """ for cmd in [" mount /filesystems ", " scanner_start"]: try: out, err, ret = run(cmd, timeout=3600) if ret != 0: logging.error("Can't run %s got %s (%d)!" % (cmd, err,

Re: Ignore error with non-zero exit status (was: How to ignore error with anon-zero exit status)

2015-12-20 Thread Ganesh Pal
> (Polite people would *ask* a *question*.) I am a polite person , sorry if the wording was harsh. > (“_a non-zero_”, with a space in-between. “anon” can be misunderstood as an > abbreviation for “anonymous”.) It was a typo. > Most simple solution for this: Do not use a loop. More "complicate

Re: does the order in which the modules are placed in a file matters ?

2015-12-22 Thread Ganesh Pal
Thanks to Don , Chris and Carl for sharing your view on this topic . -- https://mail.python.org/mailman/listinfo/python-list

python unit test framework sample code

2016-01-06 Thread Ganesh Pal
Hello Team, I have written a small program using python unit test framework . I need your guidance to find out 1. If I have used the fixtures and classes properly ( first oop program) :) ) 2. why does unittest2.SkipTest not print the message when the failures are encountered ? 3. Also sys.stderr

Fwd: python unit test framework sample code

2016-01-10 Thread Ganesh Pal
Apologies, looks like I did a reply instead of reply-all. So forwarding this email , please provide guidance on the same -- Forwarded message -- From: Ganesh Pal Date: Thu, Jan 7, 2016 at 12:26 PM Subject: Re: python unit test framework sample code To: Terry Reedy > Unless

Re: Fwd: python unit test framework sample code

2016-01-11 Thread Ganesh Pal
Totally stuck with this On Jan 10, 2016 7:11 PM, "Ganesh Pal" wrote: > Apologies, looks like I did a reply instead of reply-all. So > forwarding this email , please provide guidance on the same > > -- Forwarded message ---------- > From: Ganesh Pal > Date:

TypeError: not all arguments converted during string formatting

2016-02-17 Thread Ganesh Pal
Hi Team, Iam on python 2.6 and Linux , I had replaced print out, err ret with logging.info(out, err ,ret) in the below code . I am getting "TypeError: not all arguments converted during string formatting" error any quick suggestion try: out, err, ret = run(cmd, timeout=60)

Re: TypeError: not all arguments converted during string formatting

2016-02-17 Thread Ganesh Pal
I think logging.info(out) works the problem is when I add logging.info(out,err,ret) ,may be there is a better way to supply this arguments On Wed, Feb 17, 2016 at 7:28 PM, Ganesh Pal wrote: > Hi Team, > > > Iam on python 2.6 and Linux , I had replaced print out, err ret with >

Re: TypeError: not all arguments converted during string formatting

2016-02-18 Thread Ganesh Pal
On Wed, Feb 17, 2016 at 7:32 PM, Chris Angelico wrote: > The print statement/function happily accepts multiple arguments, and > will join them according to a set of predefined rules. The logging > functions don't have those rules, so they take one message and some > optional parameters. Try this,

Python unittest2.SkipTest and general suggestion

2016-02-21 Thread Ganesh Pal
Hello team, Please provide your guidance on how to proceed with the below test , Iam on python 2.6 and Linux. I have a linitation to use python 2.6 and unittest2 try: import unittest2 as unittest except ImportError: import unittest class isiCorruptTest(unittest.TestCase): corrupt_

can try expect have if else.

2016-02-21 Thread Ganesh Pal
Hi Team, Iam on python 2.6 , need input on the below piece of code. EXIT_STATUS_ERROR=1 def create_dataset(): """ """ logging.info("Dataset create.Started !!!") try: if os.path.ismount("/nfs_mount"): touch_file("inode_fixcrc.txt") logging.inf

Re: can try expect have if else.

2016-02-21 Thread Ganesh Pal
On Sun, Feb 21, 2016 at 10:37 PM, Ben Finney wrote: > What result do you get when running that code? What empirical reason do > you have to think it would work or not work? I wanted to know was is it good to have if else with in a try expect block , I was checking more from the programming pers

Re: Python unittest2.SkipTest and general suggestion

2016-02-21 Thread Ganesh Pal
On Sun, Feb 21, 2016 at 10:33 PM, Ben Finney wrote: > You are already supplying a custom message to ‘self.skipTest’:: > > except Exception as exc: > logging.error(exc) > raise unittest.SkipTest("Failure running Integrity Scan ") > > So you can change that message by including

How to remove the line numbers from the file in python

2016-02-26 Thread Ganesh Pal
what would be the easiest way to remove the lines in the leading numbers 1.e 1 ,2, 19 from this file using python ? 1 import os 2 Suite = "Test Mail" 3 4 def sendMail(x): 5 text = x 6 sendmail_location = "/home/prasad/onefs/share/sendmail" # sendmail location 7 p =

Re: How to remove the line numbers from the file in python

2016-02-27 Thread Ganesh Pal
Thanks it works fine :) On Fri, Feb 26, 2016 at 5:01 PM, Peter Heitzer wrote: > Ganesh Pal wrote: >>what would be the easiest way to remove the lines in the leading >>numbers 1.e 1 ,2, 19 from this file using python ? > import sys,re > for line in sys.stdin: >

list index out of range Error , need to fix it or ignore it

2016-02-27 Thread Ganesh Pal
Iam on python 2.6 and Linux , I need input on the below program , here is the spinet of my program filename='/tmp2/2.txt' def check_file(): """ Run the command parallel on all the machines , if there is a file named /tmp/file2.txt extract file2.txt """ global filename bad

Re: list index out of range Error , need to fix it or ignore it

2016-02-27 Thread Ganesh Pal
changed baddr="" to file ="" in the example program , sorry for the typo > filename='/tmp2/2.txt' > > def check_file(): > """ > Run the command parallel on all the machines , if there is a > file named /tmp/file2.txt extract file2.txt > > """ > global filename > file = '' >

Re: list index out of range Error , need to fix it or ignore it

2016-02-28 Thread Ganesh Pal
>> > what is run(...) > The run (_ is a wrapper it uses suprocess.Popen and returns stdout ,error and extitcod e > not a good idea to have catchall exception how to fix this ? > >> > return False >> > if __name__ == '__main__': >> > main() >> > >> -- >> > copy and paste your tr

usage of try except for review.

2016-02-29 Thread Ganesh Pal
Iam on python 2.6 and Linux , need your suggestion on the usage of try and except in this program and Modified code: #!/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, timeo

Re: usage of try except for review.

2016-02-29 Thread Ganesh Pal
Iam really sorry , I will have to resend my question again , because the earlier post had mistakes and formatting was bad , so apologies for top posting will try to avoid such mistakes in future. Iam on python 2.6 and Linux , need your suggestion on the usage of try and except in this program #

common mistakes in this simple program

2016-02-29 Thread Ganesh Pal
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 lo

Re: common mistakes in this simple program

2016-02-29 Thread Ganesh Pal
On Mon, Feb 29, 2016 at 9:59 PM, Ian Kelly wrote: > On Mon, Feb 29, 2016 at 8:18 AM, Ganesh Pal wrote: >> Iam on python 2.6 >> 1. usage of try- expect > > try-except in every single function is a code smell. You should only > be using it where you're actually goin

Re: usage of try except for review.

2016-02-29 Thread Ganesh Pal
On Mon, Feb 29, 2016 at 10:10 PM, Dennis Lee Bieber wrote: > Ask yourself: Will my program still work if I remove all the assert > statements. If the answer is "No", then you should not be using an assert. You meant if the answer is "NO" then I should be using asset ? > Can your

Re: usage of try except for review.

2016-02-29 Thread Ganesh Pal
> No, Dennis was correct. You should assume that "assert" can > potentially be replaced with "pass" and your program will continue to > work. Thanks Chris for clarifying Dennis point of view , >>try: >>if not run_cmd_and_verify(cmd, timeout=3600): > > Since your vers

Re: usage of try except for review.

2016-02-29 Thread Ganesh Pal
> I have tried down the code to Read "I have tried down the code to " as I have trimmed down the code as below Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Re: common mistakes in this simple program

2016-02-29 Thread Ganesh Pal
>> How do we reraise the exception in python , I have used raise not >> sure how to reraise the exception > > raise with no arguments will reraise the exception currently being handled. > > except Exception: > logging.error("something went wrong") > raise Thanks Ian for taking time and lo

Re: common mistakes in this simple program

2016-02-29 Thread Ganesh Pal
On Mar 1, 2016 12:06 AM, "Chris Angelico" wrote > > You're falling into the trap of assuming that the only exception you > can ever get is the one that you're planning for, and then handling. Ok sure ! > ALL exceptions as though they were that one. Instead catch ONLY the > exception that you're

Re: common mistakes in this simple program

2016-03-15 Thread Ganesh Pal
On Tue, Mar 1, 2016 at 2:41 AM, Martin A. Brown wrote: > Please read below. I will take a stab at explaining the gaps of > understanding you seem to have (others have tried already, but I'll > try, as well). > > I am going to give you four different functions which demonstrate > how to use excep

Python Fabric on Windows :

2014-10-26 Thread Ganesh Pal
Hi Team , Iam new to Fabric and Iam using the fab command-line tool to run a set of task on Linux clients. I just started coding and Iam pretty new to fabric, Iam hoping I will be able to launch my fabric scripts from both Windows and Linux Machine . Installing Cygwin might help in wi

Re: Python Fabric on Windows :

2014-11-01 Thread Ganesh Pal
On Tue, Oct 28, 2014 at 5:00 PM, Robin Becker wrote: > > I found fabric on windows quite hard, but I have managed to use it. For > ssh I think I had to use the putty tools eg plink to do remote work. > > On the other hand I find plumbum much easier > > http://tomerfiliba.com/blog/Plumbum/ > > Than

  1   2   >