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

2020-08-10 Thread Ganesh Pal
stat['server2'] = ast.literal_eval(stat['server2']) ... >>> I tried startswith() and endswith(), doesn't seem to work ?. Is there a simpler way ? Regards, Ganesh On Tue, Aug 11, 2020 at 4:06 AM MRAB wrote: > On 2020-08-10 19:35, Ganesh Pal wrote: > > How to remo

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

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

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): > > '''Do

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: 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 >

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,

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

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

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)]*

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

2018-06-17 Thread Ganesh Pal
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 Sat, Jun 16, 2018 at 11:12 PM, Peter Otten <__pete...@web.de> w

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: 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)

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

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

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

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

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 .

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

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-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

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 >>>

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

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 < steve+comp.lang.pyt...@pearwood.info> 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

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

2018-03-15 Thread Ganesh Pal
-l [-d] [-u] [address_family] ifconfig [-L] [-C] [-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

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 = '||' +

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 --

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:

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

Re: Python string replace the values

2017-09-02 Thread Ganesh Pal
MRAB , Thanks for your solution it looks neat and best ! On Fri, Sep 1, 2017 at 11:14 PM, MRAB <pyt...@mrabarnett.plus.com> wrote: > On 2017-09-01 18:13, Ganesh Pal wrote: > >> In the fixed length string i.e "a",last 4 bits i.e "" should be

Re: Python string replace the values

2017-09-01 Thread Ganesh Pal
Fri, Sep 1, 2017 at 11:16 PM, Rhodri James <rho...@kynesim.co.uk> wrote: > On 01/09/17 18:13, Ganesh Pal wrote: > >> "a" + "1"===> expected was a0001 >>>>> >>>> 'a1' >> > > Why would you expect that? Conca

Re: Python string replace the values

2017-09-01 Thread Ganesh Pal
> (I assume that in your example "a" and "aa" => c00aa, that really should have been a00aa) Yes , thanks for noticing. On Fri, Sep 1, 2017 at 11:18 PM, Irv Kalb <i...@furrypants.com> wrote: > > > On Sep 1, 2017, at 10:13 AM, Ganesh Pal <ganes

Python string replace the values

2017-09-01 Thread Ganesh Pal
In the fixed length string i.e "a",last 4 bits i.e "" should be replaced by the user provided value ( the value is between 0001 + f f f f ) . I intend to form final_string using a fixed_string and an user provided user_string Example: fixed_string = "a" user_string ='1' final

Multiple try expect in a for loop

2017-08-22 Thread Ganesh Pal
Hello python friends, I need a suggestion on the below piece of code . I have for loop and I need to do the below i.e create 100 of queue ,open ,and append some data to a data structure. Is multiple try except the way to go or any other idea's. I feel that there is a better way to write

unpacking elements in python - any tips u want to share ?

2017-07-27 Thread Ganesh Pal
Hello Python friends , I need some inputs on the efficient way to unpack the elements in python , I know this is a very basic question , just curious to know if there are better way ways to achieve it . For our initial discussion let’s start with list I have a list with say 7 elements

Tips to match multiple patterns from from a single file .

2017-07-23 Thread Ganesh Pal
I have hundreds of file in a directory from all of which I need to extract multiple values namely filename with pathname (which start with test*), 1,1,25296896:8192 ( only the one containing pattern corrupting), before corruption( it’s a hex value), offset(digit), size(digit) Sample file

Re: Best way to assert unit test cases with many conditions

2017-07-19 Thread Ganesh Pal
> > Yes. Just assert each thing as it needs asserting. > > Asserting each sub test will fail the entire test, I want the to pass the test if any the sub test passes. If the sub test fail try all cases and fail for the last one. Example : def test_this(self): if Sub_test_1():

Re: Best way to assert unit test cases with many conditions

2017-07-19 Thread Ganesh Pal
On Tue, Jul 18, 2017 at 11:02 PM, Dan Strohl wrote: > > Like this: > > Def test_this(self): > For i in range(10): > with self.subTest('test number %s) % i): > self.assertTrue(I <= 5) > > With the subTest() method, if anything within that subTest fails, it

Best way to assert unit test cases with many conditions

2017-07-18 Thread Ganesh Pal
Hi Dear Python Friends, The unittest’s TestCase class provides several assert methods to check for and report failures . I need suggestion what would the best way to assert test cases in the below piece of code. (1)

Re: Better Regex and exception handling for this small code

2017-07-18 Thread Ganesh Pal
Thanks Cameron Simpson for you suggestion and reply quite helpful :) On Wed, Jul 12, 2017 at 5:06 AM, Cameron Simpson <c...@zip.com.au> wrote: > On 11Jul2017 22:01, Ganesh Pal <ganesh1...@gmail.com> wrote: > >> I am trying to open a file and check if there is a patter

Re: Better Regex and exception handling for this small code

2017-07-11 Thread Ganesh Pal
I am trying to open a file and check if the pattern i.e initiator_crc has changed after the task got completed? * On Tue, Jul 11, 2017 at 10:01 PM, Ganesh Pal <ganesh1...@gmail.com> wrote: > Dear Python friends > > I am trying to open a file and check if there is a patter

Better Regex and exception handling for this small code

2017-07-11 Thread Ganesh Pal
Dear Python friends I am trying to open a file and check if there is a pattern has changed after the task got completed? file data: #tail -f /file.txt .. Note: CRC:algo = 2, split_crc = 1, unused

any suggestion on this code

2017-04-23 Thread Ganesh Pal
Hello Team, I have a sample code that runs through the list of dictionary and return a dictionary if the search value matched *Sample Program:* #!/usr/bin/python def return_matched_owner(dict_list,search_block): """Accepts a list of dictionary with owners and returns a dict if

Re: match.groupdict() into a single dict

2017-04-20 Thread Ganesh Pal
apologies for spamming and Sorry my bad the solution suggested by MRAB works fine : ) with open("/tmp/2.repo","r") as f: for line in f: for line in f: result = re.search(r'MSG=attempt to record(.*)LINSNAP', line) if result: subpatterns =

Re: match.groupdict() into a single dict

2017-04-20 Thread Ganesh Pal
> Why would you expect a single dictionary? You're doing 3 separate matches! > > correct, I didn't knew how to combine it all the patterns You could just combine the patterns as alternatives: > > # The alternatives are matched repeatedly. The final '.' alternative > # will consume a character

match.groupdict() into a single dict

2017-04-19 Thread Ganesh Pal
Hello friends, I am learning regex and trying to use this to my scripts I need some suggestion on the below code. I need to match all lines of a file that have a specific pattern and return them as a dictionary. Sample line: 'NODE=ADAM-11: | TIME=2017-04-14T05:27:16-07:00 | COND=Some lovely

Optimize this code further

2017-04-04 Thread Ganesh Pal
Dear friends. I am trying optimize the below sample code any suggestion on this please let me know yy-1# cat file1.py #! /usr/bin/python from __future__ import absolute_import, division, print_function import os import sys import logging logging.basicConfig(stream=sys.stderr,

Re: Basic Nested Dictionary in a Loop

2017-04-04 Thread Ganesh Pal
Thanks Peter , Terry and others ! On Tue, Apr 4, 2017 at 12:11 PM, Peter Otten <__pete...@web.de> wrote: > Ganesh Pal wrote: > > >> > >> > >> Whenever you feel the urge to write range(len(whatever)) -- resist that > >> temptation, and you'll end up

Re: Basic Nested Dictionary in a Loop

2017-04-02 Thread Ganesh Pal
> > > Whenever you feel the urge to write range(len(whatever)) -- resist that > temptation, and you'll end up with better Python code ;) > > Thanks for this suggestion but for my better understanding can explain this further even Steve did point the same mistake. > > Instead of artificially

Re: Basic Nested Dictionary in a Loop

2017-04-02 Thread Ganesh Pal
On Sun, Apr 2, 2017 at 10:35 PM, Steve D'Aprano wrote: > > Why is payment a string? > > Yes it should be int > > > The value salary3 ,salary4,salary4 is to be generated in the loop . Iam > > trying to optimize the above code , by looping as shown below > > In the

Basic Nested Dictionary in a Loop

2017-04-02 Thread Ganesh Pal
Dear Python friend I have a nested data dictonary in the below format and I need to store 1000 of entries which are in teh below format >>> X['emp_01']['salary3'] = dict(sex="f", status="single", exp="4", grade="A",payment="200") >>> X['emp_01']['salary4'] = dict(sex="f", status="single",

C-Python and Endianness

2017-03-26 Thread Ganesh Pal
Hello Team , I want to write the hexadecimal string that is passed from python as it is on disk in C , my problem is that the values are getting stored in little endian and the values are swapped it has been quite a pain for me to fix this , any suggestion on how to fix this (I am

If statement with or operator

2017-02-22 Thread Ganesh Pal
Hello Friends, I need suggestion on the if statement in the below code , all that I was trying to do was to add a check i.e if any one of the functions return True then break the loop. end_time = time.time() + 300 umount_completed = False while time.time() < end_time: if

Re: Python - decode('hex')

2017-02-20 Thread Ganesh Pal
Got it , MRAB, Thanks for the explanation it was such a simple thing I was breaking my head over it On Tue, Feb 21, 2017 at 1:34 AM, MRAB <pyt...@mrabarnett.plus.com> wrote: > On 2017-02-20 19:43, Ganesh Pal wrote: > >> On Feb 21, 2017 12:17 AM, "Rhodri James"

Re: Python - decode('hex')

2017-02-20 Thread Ganesh Pal
On Feb 21, 2017 12:17 AM, "Rhodri James" <rho...@kynesim.co.uk> wrote: On 20/02/17 17:55, Ganesh Pal wrote: > 1. The only difference between both the programs the difference are just > the below lines. > > newdata = '64000101057804'.decode('hex') > >

Python - decode('hex')

2017-02-20 Thread Ganesh Pal
Hello Python world, I am on Linux and Python 2.7 , I need some help to figure out what is going wrong in the below piece of code I am trying to replace seven bytes in the hexdumfile at a given offset Program 1 works fine #!/usr/bin/python from qa.utils.easy_popen import run import pdb def

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

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

2016-11-28 Thread Ganesh Pal
pyt...@pearwood.info> wrote: > On Tuesday 29 November 2016 02:18, Ganesh Pal wrote: > > > On Mon, Nov 28, 2016 at 1:16 PM, Steven D'Aprano < > > steve+comp.lang.pyt...@pearwood.info> wrote: > > > >> > >> > >> There is no need to return True. The fu

Re: Simple Python equivalent for the shell command

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

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 < steve+comp.lang.pyt...@pearwood.info> 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

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

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:

How to you convert list of tuples to string

2016-11-22 Thread Ganesh Pal
= 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

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 <pyt...@mrabarnett.plus.com> 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. >&

Re: list or dictionary

2016-09-21 Thread Ganesh Pal
'Aprano <steve+pyt...@pearwood.info> wrote: > On Wed, 21 Sep 2016 04:04 am, Ganesh Pal wrote: > > > 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. > > &

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: 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 <stefan...@behnel.de> wrote: > Ganesh Pal schrieb am 01.09.2016 um 14:30: > > On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote: > >> Ganesh Pal writ

Re: C Python extension to export an Function

2016-09-01 Thread Ganesh Pal
On Thu, Sep 1, 2016 at 12:32 PM, dieter <die...@handshake.de> wrote: > Ganesh Pal <ganesh1...@gmail.com> 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 ... > > May

C Python extension to export an Function

2016-09-01 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

Re: Helloworld with Python C extension

2016-08-30 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

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

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

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

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

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

Re: re.search - Pattern matching review

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

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 >

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 3

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

2016-05-29 Thread Ganesh Pal
1376034816:8192 (block *1,0,1375772672:8192*' Regards, Ganesh On Sun, May 29, 2016 at 11:53 AM, Ganesh Pal <ganesh1...@gmail.com> wrote: > > > >> Perhaps: >> map(int, re.search(search_pat, stdout).groups()) >> >> >> > Thanks Albert

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

2016-05-29 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()) >>>

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

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

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

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

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

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)

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",

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

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 >

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

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: 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

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

Re: common mistakes in this simple program

2016-02-29 Thread Ganesh Pal
On Mon, Feb 29, 2016 at 9:59 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On Mon, Feb 29, 2016 at 8:18 AM, Ganesh Pal <ganesh1...@gmail.com> wrote: >> Iam on python 2.6 >> 1. usage of try- expect > > try-except in every single function is a code smell. You shoul

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

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

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,

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

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 = '' >

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

  1   2   >