].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 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
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
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):
>
>
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
lueError("Error getting filename or testcase no")
Regards,
Ganesh
--
https://mail.python.org/mailman/listinfo/python-list
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
>
>
>
> (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
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
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
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
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
>
{'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
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
--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
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
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
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
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
9a-fA-F]+::HEAD))',
'.']
I am using Python 2.7 + Linux
Regards,
Ganesh
--
https://mail.python.org/mailman/listinfo/python-list
>
>
> 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
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
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
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
-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
>>> 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
>
>
> 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?
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.
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
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
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
> (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
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
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
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
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
# 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
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
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
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
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
].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
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
)*' % '|'.join(subpatterns)
match = re.search(pattern, line)
print ' ', match.groupdict()
Regards,
Ganesh
--
https://mail.python.org/mailman/listinfo/python-list
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
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
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
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
>
>
> 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
'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
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
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
r , please suggest. I am on Linux and Python
2.7
Regards.
Ganesh
--
https://mail.python.org/mailman/listinfo/python-list
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
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')
>
>
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
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
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
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
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
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
-
---
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Thanks works fine : )
--
https://mail.python.org/mailman/listinfo/python-list
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
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
;, '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
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
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
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
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"
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
>
>
> 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
):
try:
create_logdir()
except Exception as e
logging.exception(e)
raise
Regards,
Ganesh
--
https://mail.python.org/mailman/listinfo/python-list
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
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
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
>> 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
> 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
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
"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
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
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
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
: %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
>>
> 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
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 = ''
>
;,
'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 - 100 of 205 matches
Mail list logo