Python Logging and printf()

2014-11-21 Thread Ganesh Pal
Hi Team , Iam using the python logging module to log the events for my application into a log file . I have set the logging level to DEBUG as shown below logging.basicConfig(filename=options.log_file, level=logging.DEBUG, format='%(asctime)s %(lev

Re: Python Logging and printf()

2014-11-24 Thread Ganesh Pal
, Chris Angelico wrote: > On Fri, Nov 21, 2014 at 9:48 PM, Ganesh Pal wrote: > > Please provide your input on the below questions. > > > > (1). How do i guarantee that all console messages will be logged into > the > > logfile ? > > (2) I feel the need to ret

PYTHON LOGGING with StreamHandler and FileHandler

2014-11-24 Thread Ganesh Pal
Hi Team, The below program logs all the messages to the log file and displays the same on the console . Please suggest how do I ensure that error and warning log levels go ONLY to stdout and/or stder Code : import logging import sys # StreamHandler root = logging.getLogger() root.setLevel(lo

Re: PYTHON LOGGING with StreamHandler and FileHandler

2014-11-25 Thread Ganesh Pal
Thanks for the hint , I was able to get the error messages on the console by setting the StreamHandler level to WARNING . It works for me know butone LAST question , it might sound simple, but Iam not able to understand the difference between - (a) ch.setLevel(logging.WARNING) and c

Python and GUI development

2014-12-01 Thread Ganesh Pal
Hi folks, I want to design a GUI interface for my project . I wanted it to use it Python and it has to work on freebsd . Please provide me the latest trends for GUI development with python. Regard s Ganesh -- https://mail.python.org/mailman/listinfo/python-list

Re: Python and GUI development

2014-12-01 Thread Ganesh Pal
Thanks for the bunch of suggestion , I have decided to go with PYQt for now : ) On Tue, Dec 2, 2014 at 4:13 AM, Rod Person wrote: > On Mon, 1 Dec 2014 23:13:32 +1100 > Chris Angelico wrote: > > > On Mon, Dec 1, 2014 at 10:55 PM, Ganesh Pal > > wrote: > > > H

Python re.search simple question

2014-12-07 Thread Ganesh Pal
Hi Folks , This might seem to be very trivial question but iam breaking my head over it for a while . My understanding is that re.search should search for the match anywhere in the string . why is re.search failing in the below case ?? >>> pattern 'Token-based migrations cannot be mixed wit

Re: Python re.search simple question

2014-12-07 Thread Ganesh Pal
Thanks guys , I escaped the '[' character and my issue is sloved .. Thank you guys u all rock :) Regards, Ganesh On Mon, Dec 8, 2014 at 12:41 PM, Zachary Ware wrote: > On Mon, Dec 8, 2014 at 12:52 AM, Ganesh Pal wrote: > > Hi Folks , > > > > This might seem

List Comprehensions

2014-12-21 Thread Ganesh Pal
Hi , (a) I was trying to reduce the below piece of code using List comprehension ? Any suggestion please let me know for opt in options: opt['result'] = Queue.Queue() tmp_thread = pause.Thread(opt) threads.append(tmp_thread) tmp_thread.start() (b)

Playing with threads

2015-01-07 Thread Ganesh Pal
Hi friends, I'm trying to use threads to achieve the below work flow 1. Start a process , while its running grep for a string 1 2. Apply the string 1 to the command in step 1 and exit step 2 3. Monitor the stdout of step1 and print success if the is pattern found Questions: 1. Can the above b

Python : writing to a file

2015-01-10 Thread Ganesh Pal
Please provide you input on the below questions: (a) I was expecting the string i.e day of week , example Saturday to be written in the file. what Iam I missing in the below program ? Program: #!/usr/bin/python import time f = open ('test_2.txt','w+b') DAY = time.strftime("%A") f.write(DAY)

Re: Playing with threads

2015-01-10 Thread Ganesh Pal
Thanks I read subprocess module this answered most of my question ,thanks a lot for the replies On Thu, Jan 8, 2015 at 9:46 AM, Terry Reedy wrote: > On 1/7/2015 9:00 PM, Ganesh Pal wrote: > >> Hi friends, >> >> I'm trying to use threads to achieve the below work

Re: Python : writing to a file

2015-01-11 Thread Ganesh Pal
On Sun, Jan 11, 2015 at 2:17 PM, Dave Angel wrote: > > > You chopped off the output there. It probably looked like this: > > > node-1# cat test_2.txt > Sundaynode-1# > > > Your output is there, right before the prompt. Since you neglected the > newline in your code, that's what you'd expect, wou

Few coding suggestions

2015-01-11 Thread Ganesh Pal
Hello Team, Iam trying to generate a file which would will should the contents in the below format # cat /root/schedule.conf Sunday 10:20 10:30 Sunday 10:30 10:40 Sunday 10:50 10:60 I have to build the above format on the local linux machine using python 2.7 version and then copy the file to

Few Coding suggestions - resending

2015-01-11 Thread Ganesh Pal
Hello Team, Iam trying to generate a file which should have the contents in the below format # cat /root/schedule.conf Sunday 10:20 10:30 Sunday 10:30 10:40 Sunday 10:50 10:60 I have to build the above format on the local linux machine using python 2.7 version and then copy the file to the

Re: Few Coding suggestions - resending

2015-01-11 Thread Ganesh Pal
On Sun, Jan 11, 2015 at 7:57 PM, Dave Angel wrote: >> >> > No idea how that represents "a difference of 5 minutes". So I'll take a > totally wild guess that you meant: > > Sunday 23:50 23:55 > Monday 00:00 00:05 > Monday 00:10 00:15 > Monday 00:20 00:25 > Monday 00:30 00:35 > > which would have

Re: Few Coding suggestions - resending

2015-01-12 Thread Ganesh Pal
On Mon, Jan 12, 2015 at 8:42 AM, Ganesh Pal wrote: > On Sun, Jan 11, 2015 at 7:57 PM, Dave Angel wrote: >>> >>> >> No idea how that represents "a difference of 5 minutes". So I'll take a >> totally wild guess that you meant: >> >> Su

Re: Few Coding suggestions - resending

2015-01-12 Thread Ganesh Pal
#x27;wb') for ii in range(10): a,b,c = gen.next() res = "{0} {1} {2} \n".format(a,b,c) print res, f.write(res) f.close() Gpal On Mon, Jan 12, 2015 at 3:23 PM, Ganesh Pal wrote: > On Mon, Jan 12, 2015 at 8:42 AM, Ganesh Pal wrote: >> On Sun, Jan 11, 20

How to terminate the function that runs every n seconds

2015-01-14 Thread Ganesh Pal
Iam using Linux and Python 2.7 and playing with the threading.Timer module. I had the below question on the same. (a) How to I prevent the execution the "EXECUTED SLEEP" after 4 seconds ? , current this is running in an infinite loop node-1# cat file_01.py import threading import time def

Re: How to terminate the function that runs every n seconds

2015-01-14 Thread Ganesh Pal
Corrected Typos . >a) How to I prevent the execution of Print "EXECUTED SLEEP" after 4 > seconds ? , current this is running in an infinite loop On Wed, Jan 14, 2015 at 6:37 PM, Ganesh Pal wrote: > Iam using Linux and Python 2.7 and playing with the threading.Timer mo

Re: How to terminate the function that runs every n seconds

2015-01-14 Thread Ganesh Pal
t : Throttling-1# python file_02.py EXECUTED SLEEP hello EXECUTED SLEEP On Wed, Jan 14, 2015 at 6:39 PM, Ganesh Pal wrote: > Corrected Typos . > >>a) How to I prevent the execution of Print "EXECUTED SLEEP" after 4 >> seconds ? , current this is running in a

Re: How to terminate the function that runs every n seconds

2015-01-14 Thread Ganesh Pal
This is bit urgent and I all stuck form last few hours :( On Wed, Jan 14, 2015 at 6:37 PM, Ganesh Pal wrote: > Iam using Linux and Python 2.7 and playing with the threading.Timer module. > > I had the below question on the same. > > (a) How to I prevent the execution the

Re: How to terminate the function that runs every n seconds

2015-01-14 Thread Ganesh Pal
> Do you want to fix the symptom, fix the problem, or finish a school > assignment? To do the first, make a global variable that contains the time > you want to stop making new threads, and conditionally test it before > calling threading.Timer > I firstly apologise for multiple posts and thanks

Python : parsing the command line options using optparse

2014-02-25 Thread Ganesh Pal
Hi Folks , Iam newbie to Python, Iam trying to use optparse module and write a script that will parse the command line options ..I had to use opt parse instead of argparse because by host Operating system is still using python 2.6 Below is the simple program ( Feel free to correct the error

Re: Python : parsing the command line options using optparse

2014-02-26 Thread Ganesh Pal
On Tue, Feb 25, 2014 at 9:55 PM, Peter Otten <[email protected]> wrote: >As you are just starting I recommend that you use argparse instead of optparse. I would love to use argparse but the script that I plan to write has to run on host machines that Python 2.6 I have freebsd clients with py

Re: Python : parsing the command line options using optparse

2014-02-26 Thread Ganesh Pal
On Wed, Feb 26, 2014 at 4:57 PM, Peter Otten <[email protected]> wrote: > > If you stick with optparse just pass the options without '=' > > -qXOR > > and > > -q XOR > > should both work. > > Thanks Peter and Simon for the hints it worked : ) without ' =' # Python corrupt.py -o INODE -p /ifs/

Re: Python : parsing the command line options using optparse

2014-02-27 Thread Ganesh Pal
> > They must be running an older version of FreeBSD since the default version > of python is 2.7. > > There is a FreeBSD package for argparse, the command would be something > like >pkg_add -r install py26-argparse > > > Rod > > Yes Iam running a older version of FreeBSD ( Iam actually run

Re: Python : parsing the command line options using optparse

2014-03-01 Thread Ganesh Pal
> > > > Thanks Peter and Simon for the hints it worked : ) without ' =' > > # Python corrupt.py -o INODE -p /ifs/1.txt -q SET -f 1 > > Current Default Choice : > > Choice: INODE > Choice: SET > Choice: 1 > > > > Iam done with the command line parsing but got stuck while trying to implement sw

Re: Python : parsing the command line options using optparse

2014-03-01 Thread Ganesh Pal
> > handler = object_type_dictionary[options.object_type] # look up the > function > handler() # call it > > The last two lines could also be merged into one > > object_type_dictionary[options.object_type]() > > but the first version may be clearer. > > Thanks for your valuable inputs all worked

Re: Python : parsing the command line options using optparse

2014-03-01 Thread Ganesh Pal
On Sat, Mar 1, 2014 at 5:17 PM, Steven D'Aprano < [email protected]> wrote: > > You should start new threads for new questions. The subject line here has > nothing to do with the questions you ask. > > Sure Steven and thanks for replying and your suggestion for Question 2 (

PEP 8 : Maximum line Length :

2014-05-13 Thread Ganesh Pal
Hi Team , what would be the best way to intent the below line . I have few lines in my program exceeding the allowed maximum line Length of 79./80 characters Example 1 : p = Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE) Iam running pylint and it says t

Optparse to parsing Suggestions !!

2014-05-30 Thread Ganesh Pal
Hello Python world , I wanted suggestion on how to modify the below code to help me accomodate the below two cases # Here is the Sample code. def main(): """ ---MAIN--- """ parser = optparse.OptionParser(usage='%prog [options] .]', version='1.0') object_choice = ('super_block','block

Re: Optparse to parsing Suggestions !!

2014-05-30 Thread Ganesh Pal
On Fri, May 30, 2014 at 7:48 PM, Ganesh Pal wrote: > > Hello Python world , > > > I wanted suggestion on how to modify the below code to help me accomodate > the below two cases > > # Here is the Sample code. > > def main(): > """ ---MAIN--

How to I do this in Python ?

2013-08-16 Thread Ganesh Pal
Hello Friends , Iam a newbie to python , Iam writing a small script that would generate various kinds of files in the specified path . Iam using sub process module to achieve this , I have stuck with few basic problems , any help on this would be great Case (a) : The below code creates the onl

Re: How to I do this in Python ?

2013-08-18 Thread Ganesh Pal
Hi Steven , Firstly thanks for responding to the question and also guiding me on how to post the question in the right order ( general to least important order ) Please find the comments >>> inline On Fri, 16 Aug 2013 11:51:32 +0530, Ganesh Pal wrote: > My goal is to create vari

Re: How to I do this in Python ?

2013-08-27 Thread Ganesh Pal
On Mon, Aug 19, 2013 at 12:57 PM, Steven D'Aprano wrote: > On Sun, 18 Aug 2013 22:36:01 +0530, Ganesh Pal wrote: > > > Please find the comments >>> inline > > Please don't do that! > > "Arrows" > are used for quoting in emails. If you prefix

fibonacci series what Iam is missing ?

2015-03-23 Thread Ganesh Pal
Hello team , [root@localhost Python]# cat fibonacci-Sequence-3.py ## Example 2: Using recursion def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-1) + fib(n-2) print fib(5) # python fibonacci-Sequence-3.py 5 what Iam I missing in the

Re: fibonacci series what Iam is missing ?

2015-03-24 Thread Ganesh Pal
On Tue, Mar 24, 2015 at 5:41 AM, Steven D'Aprano wrote: > Python does not automatically print all return statements. If you want it to > print the intermediate values produced, you will need to add print before > each return: > > > py> def fib(n): > ... if n == 0: > ... result = 0 > .

python : timeit - Tool for measuring execution time

2015-04-21 Thread Ganesh Pal
Hi Team, Iam running the below command on Linux machine have Python 2.7 installed , I was trying to figure out the speed difference between xrange and range functions. range : python -m timeit 'for i in range(100):' ' pass' 10 loops, best of 3: 90.5 msec per loop $ python -m timeit 'for i

Re: python : timeit - Tool for measuring execution time

2015-04-22 Thread Ganesh Pal
Thank you , this answers my question : ) On Apr 22, 2015 6:39 PM, "Michael Torrie" wrote: > > On 04/21/2015 09:31 PM, Ganesh Pal wrote: > > Iam not able to understand what why only 10 loops were run ? what > > does this mean and how does this work ? > >

Ignore stderr and use return code

2015-10-25 Thread Ganesh Pal
Hi Teamm In the below code, we found that the command i.e cmd = "mount /filesystem1" succeeded. But the test failed due to the weaker stderr def mount_me(): cmd = "mount /filesystem1" proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)

How to make this simple code look better

2015-10-27 Thread Ganesh Pal
from myPopen import run def configure_network(): """ Prepare network for test """ try: cmd = ("netadm enable -p ncp DefaultFixed") out, err, ret = run(cmd, timeout=60) if ret != "": logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))

Re: How to make this simple code look better

2015-10-27 Thread Ganesh Pal
> According to the format strings, 'ret' is a number. If that's the case, > it's not a string, so ret != "" will always be true. > > Why are you wrapping the command string literals in (...)? That's not > necessary. > > You're doing the same thing with each of the command strings, so why > not put

Re: How to make this simple code look better

2015-10-27 Thread Ganesh Pal
On Tue, Oct 27, 2015 at 5:38 PM, Tim Chase wrote: > It reduces the redundant code and also brings all of the commands > together in one place to see the expected steps. Thanks your suggested code looks nice , I easily knocked off half the lines of my code :) -- https://mail.python.org/mailman/l

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

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

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 att

C-Python and Endianness

2017-03-25 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 on

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

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 above example, you have strings

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-04 Thread Ganesh Pal
Thanks Peter , Terry and others ! On Tue, Apr 4, 2017 at 12:11 PM, Peter Otten <[email protected]> wrote: > Ganesh Pal wrote: > > >> > >> > >> Whenever you feel the urge to write range(len(whatever)) -- resist that > >> temptation, and you'll e

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, level=

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

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 i

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 = [r

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 th

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 =

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

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

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

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 won't > stop the

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(): #p

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 c

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 sa

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 tho

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 str

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

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

<    1   2