User Profile

Collapse

Profile Sidebar

Collapse
Benny the Guard
Benny the Guard
Last Activity: Jul 24 '10, 08:25 PM
Joined: Jun 26 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Sorry copied the wrong test code for the second example, that works. The code that acts as it should is

    Code:
    proc = subprocess.Popen('myprogram',
                            stdin=subprocess.PIPE,
                            stdout=None
                            )
    (stdoutdata, stderrdata) = proc.communicate('print hello')
    print str(stdoutdata)
    That is stdout is None not stdin, which of course would...
    See more | Go to post

    Leave a comment:


  • Not sure I see the need for a trailing comma, its the last param so no need for it. And the program does run, just not correctly.

    I tried to simplify my code and likely did too much. So here is my code.

    Code:
    proc = subprocess.Popen('myprogram',
                           stdin=subprocess.PIPE,
                           stdout=subprocess.PIPE
                           )
    (stdoutdata, stderrdata)
    ...
    See more | Go to post

    Leave a comment:


  • Subprocess not working with stdin/stdout set to PIPE

    I am trying to use the subprocess module to run an interactive tool, issue some commands via stdin, then read the results from stdout and end.

    So I do the following:

    Code:
    output = Popen(["mycmd", "myarg"], stdin=PIPE,stdout=PIPE).communicate('prompt command')[0]
    mycmd should load, write output to stdout, then prompt for data. When data is given it prints some more. Well when I...
    See more | Go to post

  • Thanks! This helps alot. I agree with Evan that this seems like a bug in Python coedecs, in that it strips the BOM from UTF-16 but not UTF-8. But adding:

    lstrip ( unicode( codecs.BOM_UTF8 , "utf8" ) )

    Works wonders. Had to use the unicode stuff to avoid an excpetion due to non-ascii characters, but it now works nicely.
    See more | Go to post

    Leave a comment:


  • More context. I loaded the file in emacs with hex mode and I see efbbbf which should indicate UTF-8. So the questions are:

    1. Why does vi show '<feff>' as the first char?
    2. Why does the first code snipet I show not strip the control character?
    3. Why when using codecs.open and forcing UTF-8 does it replace the control charcater with feff?
    4. Does Python have a way to read in a file with auto-detection...
    See more | Go to post

    Leave a comment:


  • Reading in a UTF-8 file but causing a UnicodeDecodeError exception

    I have a CSV file created by VisualBasic in UTF-8. If I open the file in vi/emacs I see the Byte-Order marker (BOM), <feff>


    So now when I read the file:

    Code:
    import codecs
    f = open ('myfile')
    test = f.readline ()
    print test.decode ('utf-8')
    It prints a control character (u'\u\xef\xbb\x bf) as its first character. Shouldn't the decode strip this? Also tried the following to...
    See more | Go to post

  • Benny the Guard
    started a topic Generating a list of tuples

    Generating a list of tuples

    Looking for the classiest way to do this, just for fun. Say you have a list of names

    Code:
    names=['george', 'paul', 'john', 'ringo']
    and a location string:

    Code:
    location='liverpool'
    Now you want to combine these into a list of tuples based on location:

    [('george','live rpool'), ('paul','liverp ool'), ('john','liverp ool'), ('ringo','liver pool')]

    Kind of like a zip function...
    See more | Go to post

  • Benny the Guard
    replied to How do i Multiply non-int by 'str'
    Two issues I see are:

    1. The variable name does not exist, the variable you mean is times
    2. raw_input returns a string, so you need to either cast it to an int with int (times) or just use the input method in place of raw_input. Should return an int.

    Good luck on the problem, you seem to be close.
    See more | Go to post

    Leave a comment:


  • Benny the Guard
    started a topic Parsing complex options in Python

    Parsing complex options in Python

    I have become familiar with optparse code to parse various options into a program. But right now having some difficulties with a new project I am working on (not a class project, just a new script).

    What I need is a command line util that can take various flags, these are 100% inclusive with no overlap. Easy, but now I want to also create some super-flags that setup a bunch of different values, and are exclusive to other super-flags....
    See more | Go to post

  • Benny the Guard
    started a topic Using DNS in python to query type MX

    Using DNS in python to query type MX

    Anyone know if python has a module to issue a query similar to:

    dig <domain> MX

    To discover server names? Rather not use 3rd party modules since this needs to run on a bunch of machines, thus one more dependency is difficult to accomodate. Thanks!
    See more | Go to post

  • Benny the Guard
    started a topic Using MixIn vs Inheritance

    Using MixIn vs Inheritance

    Working on a new design and encountering some in my group who suggest creating a bunch of MixIn classes and combining them in and others who are suggesting a more classic approach of having a base class for the common functionality and then derving for specific use cases. As I see it for Mixins to be effective and useful one should:

    a) MixIns should provide an interface but NO data storage (after all MixIns storing data may clobber...
    See more | Go to post

  • Benny the Guard
    replied to httplib timeout specification
    I know there are timeouts in sockets, but I want them in HTTPConnection objects. Either I need to import sockets and change the timeout for all sockets (which may be undesirable) or leave it at no timeout for an HTTP connection. The side question was, is there a valid/useful reason the default timeout for sockets is None thus causing potential locks in every python program.
    See more | Go to post

    Leave a comment:


  • Benny the Guard
    started a topic httplib timeout specification

    httplib timeout specification

    Seems like I am missing something. Shouldn't one be able to specify a time out on an HTTPConnection attempt? By default Python socket has no timeout (out of curiosity anyone know the history of this choice as it seems so prone to create problems) so I would expect to see one on the client's of socket. Is my only option to set the default timeout in the sockets module?
    See more | Go to post

  • Seems to work, only issue remaing is how to deal with the user column. This col can be null. And for some odd reason the code above returns eevrything that is not null, apparently in PL/SQL null != null. So I may need a IF block for this one input, but the other work well.
    See more | Go to post

    Leave a comment:


  • Ok. It was the '||' that confused me. Also the inputs may not exist. So for example statsu may not be passed in and thus should not be in the where clause. So that compilcates things some, but I guess I would build my base SQL call then conditionally add strings to it to build up things, then call EXECUTE IMMEDIATE on it.
    See more | Go to post

    Leave a comment:


  • I think this is indeed the rigth track. But not sure what the
    Code:
    '||CHR(39)||p_status||CHR(39)||'
    does. Is this some sort of conditional notation?
    See more | Go to post

    Leave a comment:


  • Benny the Guard
    started a topic Proecdure/Function with conditional inputs

    Proecdure/Function with conditional inputs

    I have a task. I have to create a query that has optional elements for a where clause. This code is needed in a few different places so I fuigured a function to create a cursor wouold be best. So I have:
    Code:
    FUNCTION get_info
    (
        p_status  IN  VARCHAR2,
        p_user     IN  VARCHAR2,
        p_type     IN  VARCHAR2
    )
    RETURN SYS_REFCURSOR;
    Now the complexity is the inputs above affect...
    See more | Go to post

  • Benny the Guard
    replied to Overloading __init__
    That works, just seems counter-intuitive since all other methods can be overloaded (and it's a basic element of OO design). If overriding __init__ is not possible, can Python really claim to be fully OO?

    What I just tried was using staticmethod factories to create it, this keeps my logic separate (and my real init logic is pretty big for each case). So I have:

    Code:
    class myclass:
    def __init__(self)
    ...
    See more | Go to post

    Leave a comment:


  • Benny the Guard
    started a topic Overloading __init__

    Overloading __init__

    Working on a class that I would use multiple constructors in C++ since I have different ways of creating the data. Tried this in python by defining multiple __init__ methods but to no avail, it seems to only find the second one. So I have:
    Code:
    class myclass:
      __init__ (self, mystring1, mystring2)
              self.name = mystring1
              self.value = mystring2
    
      __init__ (self, xmldoc):
    ...
    See more | Go to post

  • Tried both ways and Python gives an error. Specifically I see:

    Traceback (most recent call last):
    File "C:\dev\Python2 3\Lib\site-packages\python win\pywin\frame work\scriptutil s.py", line 310, in RunScript
    exec codeObject in __main__.__dict __
    File "C:\test.py ", line 19, in ?
    print ("************* *************** ******")
    File "C:\Python23\li b\site-packages\DCOrac le2.py",...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...