User Profile

Collapse

Profile Sidebar

Collapse
indiarocks
indiarocks
Last Activity: Aug 28 '07, 01:34 AM
Joined: Feb 7 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • indiarocks
    replied to Function Names on a function call
    Was playing around with bartonc's tip and found out the answer.
    [CODE=python]
    caller = inspect.current frame().f_back. f_code
    print "I was called by " , caller.co_name
    [/CODE]

    Thanks,
    -V
    See more | Go to post
    Last edited by bartonc; Jul 18 '07, 08:03 PM. Reason: Added [CODE=python][/CODE] tags.

    Leave a comment:


  • indiarocks
    replied to Function Names on a function call
    Thanks for the tip. But what if I don't know the name of function that can call common_func. It could be any arbitrary function name defined by the user who calls common_func.

    Thanks...
    See more | Go to post

    Leave a comment:


  • indiarocks
    started a topic Function Names on a function call

    Function Names on a function call

    Let's say for eg. I have one common function say 'common_func' and it can be called by any other functions. If func1, makes a call to common_func, I need to determine in common_func that this call was made by func1. If func2 makes a call to common_func, that this call was made by func2.

    I need a way to figure out which function made a function call to common_func.

    I don't know if I am making sense.

    Thanks,...
    See more | Go to post

  • indiarocks
    replied to HTTP GET/POST on remote machines
    Yup , I can use proxy but I don't want to. Anyways, thanks a lot for the help, I guess CURL would do what I was looking for.

    Thanks a bunch!!!!
    See more | Go to post

    Leave a comment:


  • indiarocks
    replied to HTTP GET/POST on remote machines
    I don't want to setup a Proxy. Ok, so here's the scenario, the PC which is running the script does not have a direct access to the destination where it needs to do the HTTP Post(coz it's on a different subnet which the script PC does not have route to). Rather it has access to a PC - say PC A which in turn has access to the destination where it can do the POST.

    So, can PC that is running the script can SSH into PC-A and then perform...
    See more | Go to post

    Leave a comment:


  • indiarocks
    replied to HTTP GET/POST on remote machines
    In that case, it is going to do a POST from the PC which is running the script. I want to isolate the PC which is running the script, not to perform any such operation.

    Anyways CURL seems to be interesting .. let me digg more into it.

    Thanks,...
    See more | Go to post

    Leave a comment:


  • indiarocks
    started a topic HTTP GET/POST on remote machines

    HTTP GET/POST on remote machines

    I need to perform HTTP Posts on a remote machine from a remote machine. Is this possible ?

    Say for eg. I ssh into a Linux Box B from my script on Linux Box A and I need to do a HTTP GET/Post from B to say google.com

    Is this possible?
    See more | Go to post

  • indiarocks
    replied to Calling init function of Parent Class
    I understand that the first init will be called and to call the init of Parent we need to explicitly say it using super. To make things more clearer, lets say A is user script and I don't want him to call super to call init of his parent. Can I do this somewhere in the background when I instantiate A....
    See more | Go to post

    Leave a comment:


  • indiarocks
    started a topic Calling init function of Parent Class

    Calling init function of Parent Class

    Let's say I have a class A which inherits from B. If I need to call the init function of B, I could just say super(A,self)._ _init__() in the init function of A.

    I was wondering how do I call the init function of B from class C, where I instantiate A.

    Usual case would be
    Code:
    Class A(b.B): 
        def __init__(self):
            super(A,self).__init__()
    What I wanted was ...
    See more | Go to post

  • indiarocks
    started a topic sending control+c using pexpect

    sending control+c using pexpect

    I need to send control+C after sending a particular command on my ssh session. How do I achieve this using Python 2.3 with pexpect?

    I tried using conn_handle.sen dline(chr(3)), but that doesn't seem to work.

    Any pointers?

    Thanks.
    See more | Go to post

  • Yeah, seems to be working well.

    Thanks...
    See more | Go to post

    Leave a comment:


  • In this case if I have my program spread across 15 files, I need to explicitly open each of the files in these 15 files. To avoid that I created a general log function which can be imported by other files and they can directly use as log(msg)...
    See more | Go to post

    Leave a comment:


  • Tried implementing the following method and it seems to work. Not sure if it's a good way to do it.

    <code>
    Code:
    file1.py 
    # Declare a global list which can be accessible by other files 
    log_list = []
    
    def func1():
       global log_list 
       log_file = file('abc.out',"w")
       log_list.append(log_file)
    
    </code>
    
    <code>
    ...
    See more | Go to post
    Last edited by bartonc; Mar 30 '07, 11:18 AM. Reason: added [code][/code] tags

    Leave a comment:


  • Creating a standard log file that is accessible by all other files

    Just a basic question, I want to create a standard log file API and want that API to be shared by all my other python files.
    For eg. I have file1 which creates a file handle and hands it over to say log.py

    Now say I have file2, and it needs to write into the same log file, how do I achieve this and what is the best way of doing it ?
    Code:
    -------
    File1:
    --------
    
    log_file = file('out.log',"w")
    ...
    See more | Go to post
    Last edited by bartonc; Mar 28 '07, 06:24 PM. Reason: added [code][/code] tags

  • indiarocks
    started a topic finding time difference

    finding time difference

    This is probably a very basic question, how do I find out the difference between two system time.

    I tried
    x1 = t1.clock
    x2 = t2.clock
    x2 - x1
    doesn't seem to give me the difference.

    Also trying this way ,

    x = time.localtime( )
    y = time.localtime( )

    tmp_time = str(x[3])+ ':' +str(x[4]) + ':' + str(x[5])

    gives me output as 11:34:5 but...
    See more | Go to post

  • Was looking around online and found this

    import sys, traceback
    Code:
    def func1()
        try:
            do something that raises exception
        except:
            traceback.print_exc(file=sys.stdout)
    That would print the stack trace.
    See more | Go to post
    Last edited by bartonc; Feb 22 '07, 08:20 PM. Reason: added [code][/code] tags

    Leave a comment:


  • Can we copy stack trace of Exception in a string?

    Hi,

    Can a stack trace be generated for the exception that the program catches using except or except IOError etc

    eg:
    Code:
      try:  
           raise Exception
      except Exception,e:
          print the stack trace that caused this exception
    Thanks
    See more | Go to post
    Last edited by bartonc; Feb 22 '07, 08:22 PM. Reason: added [code][/code] tags

  • indiarocks
    started a topic output on sys.stdout and logfile

    output on sys.stdout and logfile

    Is there a way in which the all the logging done using pexpect can be sent to stdout as well as a file.

    eg.
    filea = file('output.lo g',"w")
    ssh = pexpect.spawn(' ssh root@1.1.1.1')
    ssh.logfile = filea
    ssh.expect('*as sword',timeout= 5)
    ......

    In the above script, the output would be stored only in the logfile, is there a way in which it can be even be sent to sys.stdout at...
    See more | Go to post

  • indiarocks
    started a topic Using getattr in Python

    Using getattr in Python

    Just a basic question .... When using getattr for a specific method from a different class, can we somehow tell getattr to do a case-insensitive search.

    Say for eg. m = getattr(obj.__c lass__,'SetupCl ass') where obj is a object of a specific class.

    If SetupClass is declared as setUPClass or in any other way, the return value of m is going to be None, so can this be avoided in any way

    Thanks
    See more | Go to post

  • indiarocks
    started a topic Using Object Oriented Design approach

    Using Object Oriented Design approach

    I have been developing a application in Python which instantiates objects on the fly. I want to adopt a Object Oriented approach in what I am developing.
    So far what I have been doing is

    Script 1 does all the argument passing and creates a Hashed data structure which is global. It in turn instantiates script2 on the fly which is passed as command line to which the global hashed data structure is passed.

    Now if...
    See more | Go to post
No activity results to display
Show More
Working...