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

Intitalize values for a class

2018-11-23 Thread Ganesh Pal
ow class such that 1. Intitalize default values if nothing is supplied by the username i.e self.params = {'id': '1', 'name': 's-1'} 2. I need to raise an Exception if the value for the key params[id] is '0'. 3. It should work if params[I'd] has values other than (1) and (2) Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

2018-07-21 Thread Ganesh Pal
lueError("Error getting filename or testcase no") Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Better way / regex to extract values form a dictionary

2018-07-21 Thread Ganesh Pal
7;filename'] fname, testcase = return_filename_test_case(path) print fname, testcase op: qerzvd-1# python filename.py ['test04_Failures.log'] ['test04'] Please suggest how can this code can be optimized further looks messy , what would be your one liner

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

try except inside a with open

2018-07-20 Thread Ganesh Pal
somedict.values()]] except (ValueError,IOError) as e: print e except IOError as e: PS: I don't want to use other way of opening file say file = open(“testfile.txt”,”w”) and also want to retain modify_various_line(f) function , Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

write the values of an ordered dictionary into a file

2018-06-21 Thread Ganesh Pal
fd.write("%s" % (value)) *output:* *root@X1:/Play_ground/SPECIAL_TYPES# cat /tmp/student_record.txt* *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||* *||John* *||28* *||13* *||2018* (2)Any alternative way to solve this easily and store the data in the requested format (can I still use cvs writer to format this) I am a Linux user with Python 2.7 Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

For specific keys , extract non empty values in a dictionary

2018-06-16 Thread Ganesh Pal
print args_dict o/p: root@X1:/Play_ground/DICT# python hello.py {'nine': 9, 'three': 3, 'one': 1} Also, Is unpacking the elements in the o_num dictionary as shown below fine or are there any other alternatives arg1, arg2, arg3, arg4, = map(args_dict.get, ('one', 'three', 'seven', 'nine')) print arg1, arg2, arg3, arg4 I am a Python 2.7 user and on Linux box Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

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
--loc=(\d+)" r_struct = r'--struct=(\w+)' if re.findall(r_loc, line): print re.findall(r_loc, line) if re.findall(r_struct, line): print re.findall(r_struct, line) root@X1:/# python regex_02.py ['0'] ['data_block'] I am a Linux user with python 2.7 Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

2018-05-10 Thread Ganesh Pal
m with subprocess or make changes in standalone_tool.py to return 0 or -1( use sys.exit()) Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

2018-05-10 Thread Ganesh Pal
atus of the shell, Is there an easy way to print Failure or success based on the value returned by python standalone_tool.py . I am on Linux with Python 2.7 and sorry for the longish post Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Converting list of tuple to list

2018-03-29 Thread Ganesh Pal
t;> for i in range(len(list_tuple)): ... element = list_tuple[i] ... ex_element = "%s,%s,%s:%s" % (element[0], element[1], element[2], element[3]) ... expected_list.append(ex_element) ... >>> expected_list ['1,2,1412734464:280', '2,5,1582956032:351

Re: String Formatting with new .format()

2018-03-28 Thread Ganesh Pal
t;> print "Retry attempt:{0} for error:{1}".format(attempts,msg2) // With Values Retry attempt:1 for error:Hello >>> Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Pep8 for long pattern

2018-03-27 Thread Ganesh Pal
9a-fA-F]+::HEAD))', '.'] I am using Python 2.7 + Linux Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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
attempt:1 for error:Hello OR >>> attempts = 1 >>> msg2 = "Hello" >>> print "Retry attempt:{0} for error:{0}".format(attempts,msg2) Retry attempt:1 for error:1 >>> PS : This is the silly question but I wanted to know if it really makes any differ

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

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
-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
>>> values = '||' + '||'.join(map(str, value_list)) + '||' >>> values '||1||2||3||4||56||s||' Iam joining the elements at the beginning and end of the list using '+' operator any other solution, this is not looking neater I am a

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?

How to ingore "AttributeError: exception

2017-09-22 Thread Ganesh Pal
te 'data' " error Any suggestion on how this can be handled better , Will ignoring the exceptions in try -except with pass be good or are there easier ways ) , try: Z_block = block.data.data.di_data.data[0][0]except AttributeError as e: pass I am a Linux user on Python 2.

How do I check all variables returned buy the functions exists

2017-09-15 Thread Ganesh Pal
es() # check if its not none # I think this can be better if value1 and value2 and value3 : print "continue with the program" else: print "Exting the program" # python file.py continue with the program I am a Linux user with Python 2.7 Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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 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 >> replaced by the user provided v

Re: Python string replace the values

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

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 wrote: > > > On Sep 1, 2017, at 10:13 AM, Ganesh Pal wrote: > > > > In the

Python string replace the values

2017-09-01 Thread Ganesh Pal
r += or it's append the value at the end of the string >>> "a" + "1"===> expected was a0001 'a1' I am on python 2.7 and Linux , any ideas that you recommend to handle this Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Multiple try expect in a for loop

2017-08-22 Thread Ganesh Pal
sys.stderr.write('Unable to open or append Queue %s: %s\n' % (q_name, str(e))) return False return True Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

2017-07-27 Thread Ganesh Pal
code using slices, >>my_list[] 1 4094 2 4th element 5th element 2 4094 01 >>> my_list[-2] 4094 >>> my_list[1] 4094 >>var1 = my_list[-2] >> var 2 = my_list[1] >>> if len(my_list) == 8: ...if my_list[-2] == my_list[1]: ... pr

Tips to match multiple patterns from from a single file .

2017-07-23 Thread Ganesh Pal
x = m.group().split() print filename , x[-1] x123-45# python test.py /var/01010101/test01_.log 1,1,25296896:8192 I am on Python 2.7 and Linux Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

2017-07-19 Thread Ganesh Pal
# Then pass test_this() and don't run next test i.e. sub_test_4() ,sub_test_5(). etc) Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

2017-07-19 Thread Ganesh Pal
if not library.is_corruption_reparied(): 41 assert False, "Corruption not reported,fixed and auto repaired.\n" 42 Let me know if it isn't clear I can give you more examples , Thanks for responding Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Best way to assert unit test cases with many conditions

2017-07-18 Thread Ganesh Pal
not fixed \n" 51 52 if not library.is_corruption_reparied(): 53 assert False, "Corruption not reported,fixed and auto repaired.\n" 54 55 @classmethod 56 def tearDownClass(self): 57 """ Delete all files """ 58 os.system("rm -rf /tmp/files/") 59 60 if __name__ == '__main__': 61 unittest.main() I am a Linux user with Python 2.7. Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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 wrote: > On 11Jul2017 22:01, Ganesh Pal wrote: > >> I am trying to open a file and check if there is a pattern has changed >> after the task got complete

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 wrote: > Dear Python friends > > I am trying to open a file and check if there is a pattern has changed > after

Better Regex and exception handling for this small code

2017-07-11 Thread Ganesh Pal
].strip() logging.info("checksumbefore :%s and checksumafter:%s" % (checksumbefore, checksumafter)) if checksumbefore == checksumafter: raise Exception("checksum not macthing") I am on Linux and Python 2.7 Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

any suggestion on this code

2017-04-23 Thread Ganesh Pal
name__ == '__main__': main() *Sample o/p:* yy-1# python stack1.py {'real_owner': '1:0120', 'fake_owner': 'ab', 'Block': '31115674'} Matching owner found Couple of question here : 1. Any better suggestion to optimize the code and any other observations around use of assert, generators and are exception handled correctly in return_matched_owner() Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Re: match.groupdict() into a single dict

2017-04-20 Thread Ganesh Pal
)*' % '|'.join(subpatterns) match = re.search(pattern, line) print ' ', match.groupdict() Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Re: match.groupdict() into a single dict

2017-04-20 Thread Ganesh Pal
way to escape * ? > /tmp/final_01.py(17)() -> pattern = '(%s)*' % '|'.join(subpattern) (Pdb) n > /tmp/final_01.py(18)() -> match = re.search(pattern, line) (Pdb) pattern '((|?|P|<|B|l|o|c|k|>|(|\\|d|+|,|\\|d|+|,|\\|d|+|:|\\|d|+|)|))*' (Pdb) n error: error('n...repeat',) Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

match.groupdict() into a single dict

2017-04-19 Thread Ganesh Pal
o add these element {'Block': '1,0,17080320:8192'} , {'p_owner': '1:0070:001a::HEAD'} ... etc to new dictionary (b) or some better regex may be the for loop is not needed and complied pattern can be better. I am a Linux user and on Python 2.7 , Thanks in advance :) Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Optimize this code further

2017-04-04 Thread Ganesh Pal
same and I am supposed to retain the same directory structure and logging Here is what I plan to do : 1. Use dictionary and Change testcases variable as dictionary and let its key store the subtest cases , so we have a nested dictionary testcase = {} testcase[‘Test_inode_1’] = createTestCases(LOG_DIR) 2.Since I need to retain the same logging directory structure , maybe I should try to get the key first and then append it to the log file Question : 1. Any other simple tips and tricks to solve the problem , I am a Linux user using python 2.7 Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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 e

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 blow

Re: Basic Nested Dictionary in a Loop

2017-04-02 Thread Ganesh Pal
'grade': 'A', > 'payment': 200, > 'sex': 'f', > 'status': 'single'}, > 'salary5': {'exp': '4', > 'grade': 'A', > 'payment': 400, > 'sex': 'f', > 'status': 'single'}, > 'salary6': {'exp': '4', > 'grade': 'A', > 'payment': 500, > 'sex': 'f', > 'status': 'single'}}} > > > > Thanks ; Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Basic Nested Dictionary in a Loop

2017-04-02 Thread Ganesh Pal
7;emp_01': {0: {'grade': 'A', 'status': 'single', 'payment': 100, 'exp': '4', 'sex': 'f'}, 1: {'grade': 'A', 'status': 'single', 'payment': 200, 'exp': '4', 'sex': 'f'}, 2: {'grade': 'A', 'status': 'single', 'payment': 400, 'exp': '4', 'sex': 'f'}, 3: {'grade': 'A', 'status': 'single', 'payment': 500, 'exp': '4', 'sex': 'f'}}} >>> Any other suggestion , Please let me know I am on python 2.7 and Linux Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

C-Python and Endianness

2017-03-25 Thread Ganesh Pal
10 e0 01 04 00 01 00 00 00 02 00 00 00 00 00 00 00 || After : 0010 23 51 34 12 ef cd ab 00 02 00 00 00 00 00 00 00 |#Q4.....| ==> 1. I am on a little endian machine and is there a way that I can stop this translation and write the values as it ( looks like we are swapping the bytes )? 2. The value passed i.e op_value is a string and its getting printed correctly at C layer,my value is always a hex decimal string of size 14 or 7 bytes. 3. Is there something that I can take care in python layer to avoid this swap ? Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

If statement with or operator

2017-02-22 Thread Ganesh Pal
r , please suggest. I am on Linux and Python 2.7 Regards. Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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 wrote: > On 2017-02-20 19:43, Ganesh Pal wrote: > >> On Feb 21, 2017 12:17 AM, "Rhodri James" wrote: >> >> On 20/02/1

Re: Python - decode('hex')

2017-02-20 Thread Ganesh Pal
On Feb 21, 2017 12:17 AM, "Rhodri James" 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
ix this in program 2 ? for my eyes there doesn't look any difference . question 2: I am using the variable newdata because I can't hardcore the value , I have to keep changing this every time the function is called, will return it as a string help me slove this problem def get_data() : return str(data) new_data =get_data(input) Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

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

2016-11-28 Thread Ganesh Pal
lang.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 Tr

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

Simple Python equivalent for the shell command

2016-11-28 Thread Ganesh Pal
number associated with each employee id """ out, err, rc = run("employee_details ls", timeout=600) emp_unum="" if rc != 0: return False for line in out.split('\n'): if emp_id in line: emp_unum = line.split

correct way to catch exception with Python 'with' statement

2016-11-27 Thread Ganesh Pal
- --- What will be the best way to catch the exception in the above program ? Can we replace both the with statement in the above program with something like below try: for i in range(1000): with open(os.path.join(QA_TEST_DIR,"filename%d

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

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

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

list or dictionary

2016-09-20 Thread Ganesh Pal
return id what's a better option here 1. store it in list and grep for id and return 2. store it in dict as key and value i.e hostname = { 'hostname1': 1} and return key 3. any other simple options. Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

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

C Python extension to export an Function

2016-08-31 Thread Ganesh Pal
size = _BSIZE; return OK; } So the primary challenge when writing a wrapper for a single function is figuring out how to get the arguments from Python form to C form, and how to get the result back to Python form. Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Re: Helloworld with Python C extension

2016-08-29 Thread Ganesh Pal
Chris for the clue's it worked, I was just wondering how could the C extension be debugged ? We have pdb at python side and gdb for C , can we run gdb on python side ? if there is a crash like the one we saw in the above diff we are clueless of what's happening? any idea or r

Helloworld with Python C extension

2016-08-29 Thread Ganesh Pal
rns the character entered for a given index"}, >>> import as.ds.dss as daa >>> print dda.dda_hello(1) zsh: segmentation fault (core dumped) python Apologies for posting the diff , I didn't find a better way Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

use import *

2016-08-01 Thread Ganesh Pal
import * is it a good programming practice to use import * ? if answer is "NO " then are there situation where you are forced to use import * Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Re: one command on backslash and space for review

2016-07-10 Thread Ganesh Pal
ll I format number to strings using .format ?? Example >>> str(num) '100' >>> cmd = "run_parallel -za{} -s 'daemon -cf xyz; sleep 1'".format(str(num)) >>> cmd "run_parallel -za100 -s 'daemon -cf xyz; sleep 1'“. Will Something like format(str(num)) work ? it working though Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

one command on backslash and space for review

2016-07-10 Thread Ganesh Pal
1. If backslash are syntactically correct 2. " -s" , starting with a leading space , may be its not a good idea , other ways 3. Iam running sleep command on the cluster i.e , how could I make it look Python or its fine to have sleep ? Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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
ributeError Exception or any thing else ) Example : try: block = re.search('(?<=\(block )[^(]*(?=\))', stdout).group() matched = re.search(r'(\d+),(\d+),(\d+):(\d+)', block) except AttributeError logging.error(' Error: while determining the block ") Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

python parsing suggestion

2016-05-30 Thread Ganesh Pal
trip().split('\n')[0].split()[6][:-1] sufficient do I need to add extra check ? it looks fine for me though. 2. Better ways to achieve the same output we need to parse is a string 3. Is re.search(r'(\d+),(\d+),(\d+):(\d+)', parent_block) needed ? I added as an extra check ,any ideas on the same Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

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

2016-05-28 Thread Ganesh Pal
arch_pat, stdout).groups()) >>> print block ['1,2:122'] >>> s1 = ','.join(str(n) for n in block) >>> print s1 1,2:122 >>> str(s1) '1,2:122' Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

2016-05-28 Thread Ganesh Pal
rning('Error reading lines from "%s" (%s).' % (cmd, e)) if block is None: logging.error("block not found") return False logging.info("block not found") return block Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

re.search - Pattern matching review

2016-05-28 Thread Ganesh Pal
ng.warning('Error reading lines from "%s" (%s).' % (cmd, e)) if block is None: logging.error("block not found") return False logging.info("block not found") return block Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Re: Skipping test using unittest SkipTest and exit status

2016-05-14 Thread Ganesh Pal
errors=1) 2. I find assert and raise RunTimeError also fitting my program ,please suggest whats best form unittest fixture point of view. if not self.scan: logging.error("Failed scanning ") assert False, "Class setup failed skipping test"

Skipping test using unittest SkipTest and exit status

2016-05-13 Thread Ganesh Pal
AIN--- """ try: unittest.main() except Exception as e: logging.exception(e) sys.exit(1) if __name__ == '__main__': main() Sample output gpal-ae9703e-1# python unitest1.py ERROR:root:Failed scanning s -- Ran 0 tests in 0.000s OK (skipped=1) Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

sys.exit(1) vs raise SystemExit vs raise

2016-04-12 Thread Ganesh Pal
): try: create_logdir() except Exception as e logging.exception(e) raise Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

how to optimize the below code with a helper function

2016-04-04 Thread Ganesh Pal
bject="baddr", offset="100", size="5", optype="set") (1) Any tips how I can optimize this i.e test case, should have a helper function that all test cases call. (2) Also note that failure.run_tool function can have variable number of argments how to handle this in the helper function? Thanks in advance Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

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-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: 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
for cmd in ["mount /nfs_mount1", "mount /cifs_mount1"]: try: if not run_cmd_and_verify(cmd, timeout=3600): logging.error("mount Failed") return False except: pass logging.info(&q

Re: usage of try except for review.

2016-02-29 Thread Ganesh Pal
"mount /nfs_mount1", "mount /cifs_mount1"]: try: if not run_cmd_and_verify(cmd, timeout=3600): return False except: pass logging.info("Setup and Creation Done !!!") Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

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

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: usage of try except for review.

2016-02-29 Thread Ganesh Pal
ption as e: logging.error("Failed to run %s got %s" % (cmd, e)) return False return True #script_10.py Failed to run mount /nfs got ERROR (ret 1): out: host-44-3 exited with status 1 err: host-44-3: mount_efs: on /nfs: efs is already mounted 3. my function def has 1000 but Iam using 3600 in the calling fnx etc , Time out value are overwritten ? 4. Any further improvement particularly on try -except ? Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

usage of try except for review.

2016-02-29 Thread Ganesh Pal
: %s\nerr: %s\n" % (ret, out, err) except Exception as e: logging.error("Failed to run %s got %s" % (cmd, e)) return False return True #script_10.py Failed to run mount /nfs got ERROR (ret 1): out: host-44-3 exited with status 1 err: hos

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

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
;, 'machine-4 exited with status 1', 'machine-5 exited with status 1', 'machine-3 exited with status 1'] ERROR:root:list index out of range 3. Any other tips to improve the program Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list

  1   2   3   >