Thread: Frustrated

Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    Frustrated


    I am attempting to create a python script that takes two files, runs diff on them, and outputs the results to a file.

    Here is the code:

    Code:
    #!/usr/bin/python
    
    import os
    import subprocess
    import sys
    
    #sys.stdout = open("test1.txt", "w")
    
    mfile = open("test1.txt", "w")
    
    #os.popen("diff patrickstar.pl patrickstar.pl~", "sys.stdout")
    os.popen("diff patrickstar.pl patrickstar.pl~", mfile.name())
    The commented lines represent previous attempts.

    I keep getting errors about broken pipes, the interpreter first complained that I needed a string for argument 2, then complained that "string object was not callable" when a string was placed in for argument 2.

    Any help would be appreciated.
    Any help would be appreciated.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481

    Self help


    Python is so well documented you often don't even need to read the manual.
    Code:
    >>> import os
    >>> help(os.popen)
    Help on built-in function popen in module posix:
    
    popen(...)
        popen(command [, mode='r' [, bufsize]]) -> pipe
        
        Open a pipe to/from a command returning a file object.
    We discover that the second argument is a string, a string that specifies the mode.

    Code:
    the_read_pipe = os.popen("diff patrickstar.pl patrickstar.pl~", 'r')
    differences = the_read_pipe.realines()
    Please read the python manuals before you try to write more python. You're really lost.

    If you're using emacs I recommend the emerge command to compare files.
    Last edited by b49P23TIvg; December 20th, 2012 at 12:41 PM. Reason: whoops!
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    that's OK


    Been awhile since I programmed anything. Been even longer since I wrote any code in Python (and most of it was in NumPy).
    Found a simpler and more intuitive way to do it in c shell.
    Considering that and your obnoxious response to an honest question, I think I have what I need without using Python.
    But thanks, anyway!!!
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481
    The emacs emerge-{buffers|files} are great commands. I suspect you might use emacs since emacs writes backup.files~ .

    Self help in python is terrific. Did you know about __doc__ strings?

    And yes, if you can use the shell instead of python that's the way to go.

    'sys.stdout' and mfile.name() are sufficiently boneheaded mode arguments to prove you didn't try.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    and try again I will certainly not!!!


    Or at least not attempt to use this forum again.
    You, sir, are very lost when it comes to pedagogy... And have much growing up to do.
    Goodbye.

    Comments on this post

    • b49P23TIvg agrees : And your name is booger???
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0
    Originally Posted by booger
    Or at least not attempt to use this forum again.
    You, sir, are very lost when it comes to pedagogy... And have much growing up to do.
    Goodbye.
    Yep... it is booger.
    Which is cheeky and harmless.

    Your immaturity is... well... not...
    And entirely UNhelpful.
    The continued nature of your responses only reinforces the idea that your assistance here is only about yourself and not those you espouse to be helping.

    Word of advice: people trying to learn the language (or, learning it as they are using it) are like students in a classroom. They are, in fact, students of a sort.
    One would think you would be honored that others are employing your language of choice (or, one of them) and that your "help", such as it is, would reflect that.
    It is never, EVER (yes, I am "shouting") appropriate - under any circumstances - to upbraid a student of any kind, under any circumstances. Certainly not to insult their attempts at resolving their problem, and certainly not with adjectives such as "boneheaded". If they are lost, indicate they are lost - respectfully.
    While this is far less formal than a classroom, at least comport yourself as an adult and a professional.
    Your behavior was backhandedly insulting and if I were to evaluate you as an educator, I would say that you have no business being one.
    You are certainly not behaving in any manner that could possibly be construed as "helpful".
    I will be sure to direct others I know in similar need away from this site from now on, not toward it.
    Now, good day.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    San Francisco Bay
    Posts
    1,939
    Rep Power
    1313
    1. Use subprocess.Popen, not os.popen, which is deprecated.

    2. Learn to love the Python library reference: http://docs.python.org/2/library/index.html

    3. b49P23TIvg was actually trying to help you, and your last post is ten times more immature and insulting than anything he wrote. Nobody here owes you anything.

    I should thank you, though, for the following gems:
    Originally Posted by booger
    One would think you would be honored that others are employing your language of choice (or, one of them) and that your "help", such as it is, would reflect that.
    Yes, I feel honored every time people post rubbish code on a programming forum, clearly having made no serious attempt to understand the tools they're using, and then flip out when they get called out on it.
    Originally Posted by booger
    It is never, EVER (yes, I am "shouting") appropriate - under any circumstances - to upbraid a student of any kind, under any circumstances.
    LOL! I hope the irony isn't lost on you.

    Comments on this post

    • codergeek42 agrees
    • Marbelous agrees
    Last edited by Lux Perpetua; December 21st, 2012 at 01:31 AM. Reason: Wrong link
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    hmmm....


    Originally Posted by Lux Perpetua
    1. Use subprocess.Popen, not os.popen, which is deprecated.

    2. Learn to love the Python library reference:
    This is true. It is, however, not always written in a user-friendly manner.

    3. b49P23TIvg was actually trying to help you, and your last post is ten times more immature and insulting than anything he wrote. Nobody here owes you anything.
    I believe this is what in psychology is known as "projection"....
    Referring to someone as "really lost" simply because they are (rightly, given the obfuscating nature of the documentation to the relative newbie) a tad confused about what the documentation says - again also considering the overall tone of the response - is in fact immature, elitist, clannish, and... well, insulting. As is yours (hence the projection comment).

    As also are nasty snarks at a person who has already stated they are departing the forum, with the intention of never returning.
    Hate to get into flame territory, but I have to thank you for that little gem of bravery...
    Hope the irony isn't lost on you...
    Unfortunately, I cannot LOL on that. because I find this exchange to be wholly without humor...
    Yes, I feel honored every time people post rubbish code on a programming forum, clearly having made no serious attempt to understand the tools they're using, and then flip out when they get called out on it.
    I simply do not care about the pickiness of your code. Or your demonstratedly offended sense of elitism. Was interested in getting my answer, quickly.
    I found tools more capable of doing it, getting my answer without the unnecessary pain of the frankly frivolous additional effort required through python. Python didn't have the chops to get the job done. A shell script sufficed...
    Your entire response proved my point instead of refuting it...
    This is why open source will never be the first choice of the non-programmer... "figure it out yourself" is not an answer.
    Hence the reason even DoD is switching ever more to Windows...
    These kinds of immature responses (that many tolerate - I, frankly, have grown tired of it) are one of the major reasons non-programmers and newbie programmers are so immediately discouraged...
    They ask a question and get their heads bitten off...
    Your username means "perpetual light"... I would look forward to how your next response will be an example of that... but as with my hope for assistance at the beginning of all of this, I feel that will probably be dashed...
    I would not expect you to be any kind of educator worth their salt as well, IMHO...

    Comments on this post

    • Lux Perpetua disagrees : No, thank you.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    p.s.


    The "shout" from a previous post was actually due to the fact that I kept getting error messages every time I attempted to use "bold".
    Also had some humorous errors when attempting to post my immediately previous response.
    I hope the irony isn't lost on you.
    Could tell you what the errors were that I received.
    But, considering your (lack of) assistance to date, I leave them for you to discover...
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    minor correction...


    Referring to someone as "really lost" simply because they are (rightly, given the obfuscating nature of the documentation to the relative newbie) a tad confused about what the documentation says...
    Combined with
    Please read the python manuals before you try to write more python. You're really lost.
    What I meant to say was that...
    To the casual reader, this is one big "screw you".
    Mayhaps a little training w.r.t. social skills may be in order?
    But why do that when you can bite and snark, eh Nox Perpetua?
    Last edited by booger; January 3rd, 2013 at 01:45 PM. Reason: tag issues (wow, not surprised on this forum...)
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    yep... no immaturity here...


    Hmmm....
    "No thank you"?

    Ibid...

    "booger is negative. booger is most likely a spammer and a traitor to the cause".
    Cause? If the "cause" is NOT to educate people and instead alienate and insult them, YES, I gladly partake of BOTH those labels. Though I am baffled as to how I would be a "spammer"... I believe a more accurate term might be "troll" - which I am not. Simply a limitedly skilled schmuck asking a question...

    ...and then flip out when they get called out on it.
    Pot, meet kettle!!!

    While I realize there are edit options, you do know I am taking screen captures of all this, right?

    Again, you attempt to refute my point by... well... proving it.
    I have no desire whatsoever to return here. Please don't tempt me back with further snark.

    However, I intend on keeping these screen captures to show to others - to warn them about NOT coming here for help...
    There are other places to go where you can ask a question - even if it's based on an admitted brain cramp - and NOT get chewed out for asking it...

    You do, however, make me as the user HIGHLY grateful for any attempt by my employer at getting me PAID user support...

    Good day...
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0
    Wow, feisty thread.

    Anyway, I just have a quick question because I sometimes have trouble reading Python documentation. I absolutely deplore PHP as a language but their documentation is much clearer than the Python Docs...
    popen(...)
    popen(command [, mode='r' [, bufsize]]) -> pipe
    I was always under the impression that square brackets meant optional, and in the above case it seems like mode='r' is already set as default. Why would boogers code produce an error asking for a string as the second argument ('r' according to b49P23TIvg's response) if the string is optional?
    I've read through the Python docs and the help doc but it doesn't seem any clearer to me. I ask this because I'm trying to show that the documentation isn't always clear and especially for beginners it's hard to find answers.
    @booger, just in case you come back I understand where you are coming from with more helpful answers. I regularly go through the docs 6 or 7 times looking for one thing and still can't get a solution. Googling doesn't always work either as many of the top results are just repeats of the same post on some site. I think you've flown of the handle a bit hard here but there is nothing wrong with letting people trying to help you that the docs didn't suffice or you didn't understand them.
    This is why open source will never be the first choice of the non-programmer...
    Please don't knock open-source, it has nothing to do with the responses in this thread and you'll get hit again for trolling. There is just as much bickering in closed-source related threads too.
    @b49P23TIvg: boneheaded is a bit errr, abrupt isn't it? Python may be naturally intuitive to you (2333 posts in devshed) but even with the docs it's not so straight forward for the rest of us. Sometimes it gets annoying when people presume you haven't read them either just because it's a natural and understandable thing for you as a skilled pythonist.

    Comments on this post

    • booger agrees : thank you
  24. #13
  25. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Tewksbury, MA
    Posts
    45
    Rep Power
    3
    If your username is BOOGER, you should expect to be "picked on".



    I have to admit it though. I get a HUGE laugh every time I see one of these supercillious asshats come on to a public forum and expect to teach the world manners. Sheesh, get a clue... This is the real world!
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    sigh...


    boragora,
    First, thank you. Also first, I agree that I probably did get a bit oversensitive - but I would argue with good reason. As this sort of treatment by b49P23TIvg, Marbelous, and Nox Perpetua is epidemic with respect to the open source community. One cannot deny that.
    Secondly, yes, the documentation gives the impression that the argument is optional. I find that most programming documentation seems to be written only for those already "expert" in the language.

    Marbelous:
    If your username is BOOGER, you should expect to be "picked on".
    This I actually laughed at... almost like it was an attempt at defusing the situation.
    Then came this:
    I have to admit it though. I get a HUGE laugh every time I see one of these supercillious asshats come on to a public forum and expect to teach the world manners. Sheesh, get a clue... This is the real world!
    Assertions of superciliousness may yet be another example of psychological projection; the underpinning reasons being admittedly abstruse to this reader...

    And it does not change the fact that - pedagogically speaking, Marbelous - the responses of those purporting to help on this forum are severely lacking...
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    did a cursory initial look in the DOCS on optional parameters...


    was doing a search in IDLE for this, and came up with a mess of irrelevant crap (they are STILL, however, using the standard python documentation).
    Tried online. Not much help there, either. Some references to using a container (thus letting the argument list be of variable size).
    When I get home, I can check an O'Reilly book, I suppose...
    Or I could check on this forum somewhere (they DO say to check it for these kinds of questions).
    Have the feeling all the responses will be RTFM.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo