Re: [Tutor] I apologize

2014-11-15 Thread Crush
Below was the post that was sent from the wrong email. Not sure if the first 
post went through, so in the event it did not, I will post again; if it was 
posted twice, I apologize for the redundancy. 

Subject: Re: Help understanding classes

Thank you Alan and Danny. It amazes me at the lengths you guys, as well as 
everyone else who contributes,  will go to to help explain things to us; it is 
greatly appreciated!

Alan, I decided to dumb down the learning classes just a little. By this I 
mean, I am not using Tkinter to learn classes. I am using one of the examples 
from your website, which I did change it just a little. I figured, I am having 
a hard time wrapping my head around classes and Tkinter would just add to the 
confusion. 

So, I have the below code. When I run this from terminal, it obviously prints 
“This is a test.” If I may, break the code down and ask questions as it 
pertains to the code?

#
class Message:
def __init__(self, aString):
self.text = aString

def printIt(self):
print self.text

m = Message("This is a test")
m.printIt()

##

With the first part…
class Message:
def __init__(self, aString):
self.text = aString
Will I always use “_init_” when defining the first function in a class? I 
noticed on your website, you created a class where you did not use “_init_” 
(see below). Was this because you did not define a function? 
class BalanceError(Exception): 
  value = "Sorry you only have $%6.2f in your account” 

I noticed that I can change “text” to anything and I still get the same results 
by running the code; I changed them to “blah” just as a test.

When I define a function in a class, will I always use “self” as the first 
entry in the parenthesis? 

On the next part…
m = Message("This is a test")
m.printIt()
I noticed I cannot run “printIt()” unless I make it an object i.e. “m = 
Message("This is a test”)…?” 
I noticed I could change "m = Message("This is a test”)” to "m = 
Message(raw_input()),” which works. 
What if I wanted to create a function in Message that receives text from 
another function and then prints that text instead of the text from  “m = 
Message("This is a test”)…; can I pass or return values to another function 
inside a class? The”self” is really throwing me off, when I think about 
creating different functions that do misc things just to practice. For example, 
I have a function that kills a Linux program. I just don’t see how to rethink 
that function to where it could be defined in a class?  
def kill_proc(process1):
i = psutil.Popen(["ps", "cax"], stdout=PIPE)
for proc in psutil.process_iter():
if proc.name(process1):
proc.kill()

Would it be something like…?
class processKiller:

def _init_(self): 

def kill_proc(self, process1):
i = psutil.Popen(["ps", "cax"], stdout=PIPE)
for proc in psutil.process_iter():
if proc.name(process1):
proc.kill()
Then outside of the class, call it like so…?
p = processKiller()
p.proc.kill()

Again, I am just practicing, trying to wrap my head around classes and 
understand how to create and use them.

Oh yeah, Alan I preordered your new book maybe a month or so ago. Any word on 
when it will be released and shipped?

Again, thanks. 

Bo ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python GPIO Code Help Needed

2014-10-26 Thread Crush
Could this work?

/usr/bin/env python

import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)

pin_list = ['GPIO.input(23)', 'GPIO.input(23)', 'GPIO.input(23)']

for item in pin_list:
   if item == false:
   os.system('mpg321 -g 95 a.mp3')

Bo 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Code critique

2014-10-25 Thread Crush
Thank you Peter for your example. I have the code working now and will post 
soon for eveyones benefit. 

Thank you all who took the time to help. 

Bo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Insert time into email

2014-10-20 Thread Crush
Hey thanks for the help, it worked like a charm. I will post the complete code 
soon, so others may benefit should they ever need it. 

Thanks again. 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] printing all text that begins with 25"

2014-10-02 Thread Crush
Yes the format is always the same and the IPs will always be in the 3rd 
collumn; although, the amount of whitspace that seperates column 2 and 3 may be 
different depending on how long the name is in column 2. Also all of the IPs 
will begin with a "25," so there would be no fear of having to deal with other 
IP addresses that start with anything else. 

Hamachi is VPN software and unfortunately, there is no command line argument 
that allows one to isolate the IPs. 

Bo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Subprocess help

2014-09-21 Thread Crush
Thank you Danny for your assistance. Just a couple of follow up questions to 
help me understand what is going on.

You said...

"Semantically, the command above means:
  execute "./octosetupBROADCASTER-linux_i386.bin" in an environment
that binds BYPASSROOT to "yes"."

Does the above mean "BYPASSROOT" is an environmet variable? Is this created and 
set by default by the system or is it created and set by 
"octosetupBROADCASTER-linux_i386.bin?"

The code you suggested...

"envCopy = os.environ.copy()
 envCopy['BYPASSROOT'] = 'yes'
 subprocess.Popen(["./octosetupBROADCASTER-linux_i386.bin"], env=envCopy)"

This copies the systems environment variables and stores them in the variable 
"envCopy?" What do the "[ ]'s" mean? Are the variables stored in an array or 
list and by enclosing "BYPASSROOT" in brackets, we are ultimately selecting 
"BYPASSROOT" and assinging its value to "yes?"

We then pass this to subprocess, but how does subprocess know we want 
"BYPASSROOT" to equal "yes" when we only pass on envCopy, which is coded before 
"
envCopy['BYPASSROOT'] = 'yes'?" Does python not work from top to bottom? 


Bo 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Subprocess help

2014-09-20 Thread Crush
Hey all, hope everyone is well. 

I am trying to write a script that automates a certain task I have recently 
found myself doing a lot lately.

The command I need to run is "BYPASSROOT=yes 
./octosetupBROADCASTER-linux_i386.bin"

I know how to use subprocess to execute the "./octosetup..." command, however 
the "BYPASSROOT=yes" is stumping me seeing how it is not really a unix command. 
I assume it is changing a variable within "octosetup...?" How do I get the 
"BYPASSROOT=yes" to be included in the subprocess.call? 

I know i know "root" is bad, but with this, I have no choice. 

Thanks 

Bo 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] command counter

2014-09-05 Thread Crush
My code is as follows...

count = 0
while count < 3:
  count += 1
   subprocess.Popen('command')
if count == 3:
  sys.exit()

'command' is any command. For testing, I have been using the command 'xterm' 
just so I can see it opening. As far as error and pertaining to the above code, 
if I close the xterm window, have it open back up until the counter reaches the 
specified number.  

I am basically trying to recreate in python a shell script I use. The current 
shell script runs a real long avconv/ bmdplay command and if the command stops 
running, the script will try and rerun it until count equals n number. Again, I 
am only using xterm temporarily while I try to get the logic correct. Once 
correct, I can change the command and still have the same outcome...I think. 

I am not using a function. 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Vol 127, Issue 15

2014-09-05 Thread Crush
Ok nevermind, I did not figure it out. My code...

count = 0
while count < 3:
count += 1
Subprocess.Popen('command')
if count == 3:
sys.exit()

This does not work as I want it to; it consecutively executes the command  
three times in a row. I only want it to execute once. However, if there is an 
error, I want it to try again, but only if count does not equal 3. If count 
equals 3, i want it to give up and exit or do something else.

Bo 

> On Sep 5, 2014, at 4:40 PM, tutor-requ...@python.org wrote:
> 
> Send Tutor mailing list submissions to
>tutor@python.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>tutor-requ...@python.org
> 
> You can reach the person managing the list at
>tutor-ow...@python.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> 
> 
> Today's Topics:
> 
>   1. Re: How to count vehicle? I'm trying but my code don't
>  increasing.. (Whees Northbee)
>   2. Re: How to count vehicle? I'm trying but my code don't
>  increasing.. (Steven D'Aprano)
>   3. Re: How to count vehicle? I'm trying but my code don't
>  increasing.. (Marc Tompkins)
>   4. How to detect colinearity? (Danny Yoo)
>   5. command counter (Bo Morris)
>   6. command counter (Bo Morris)
> 
> 
> --
> 
> Message: 1
> Date: Fri, 5 Sep 2014 18:09:45 +0700
> From: Whees Northbee 
> To: Danny Yoo 
> Cc: "tutor@python.org" 
> Subject: Re: [Tutor] How to count vehicle? I'm trying but my code
>don'tincreasing..
> Message-ID:
>
> Content-Type: text/plain; charset="utf-8"
> 
> I'm really sorry if my post doesn't appropriate to the forum rule.. I
> already asked in other forums 2 months ago, but no answer or had voted down
> and closed.. If you ask me about the basic slope formula or basic theory of
> intersection of point with a line I know, that's why I try with "if" code
> since the line is have the same y coordinate there's no slope, so I think
> if the y coordinate point same with y coordinate line no matter the value
> of x coordinate as long as the y coordinate same, the counter increasing..
> but if you're think I'm expert with python because I'm work with computer
> vision I'm not I'm newbie to both.. I'm sorry..
> 
> 
> On Wed, Sep 3, 2014 at 6:04 AM, Danny Yoo  wrote:
> 
>>> 
>>> On Tue, Sep 2, 2014 at 7:01 AM, Whees Northbee 
>> wrote:
 If all of these confusing, I'll simplify the problem, I need to know if
>> a
 point (x,y) exactly at a line where line is (ax1,ay) to (ax2,ay)..
>>> 
>>> 
>>> Case in point: in the question above, you can't possibly be asking us
>>> to help you write a predicate that tells whether a point is on a line.
>>> So I have to be misunderstanding your question.  You must be asking
>>> for a library function in OpenCV, and I'm pretty sure none of us are
>>> OpenCV experts.
>> 
>> 
>> Ok, found an OpenCV-specific answer about this:
>> 
>> 
>> http://stackoverflow.com/questions/5596805/opencv-detect-if-points-lie-along-line-plane
>> 
>> As expected, this is very domain-specific, and probably not suitable
>> for Python-tutor.
> -- next part --
> An HTML attachment was scrubbed...
> URL: 
> 
> 
> --
> 
> Message: 2
> Date: Sat, 6 Sep 2014 03:40:43 +1000
> From: Steven D'Aprano 
> To: tutor@python.org
> Subject: Re: [Tutor] How to count vehicle? I'm trying but my code
>don'tincreasing..
> Message-ID: <20140905174043.gq9...@ando.pearwood.info>
> Content-Type: text/plain; charset=us-ascii
> 
>> On Fri, Sep 05, 2014 at 06:09:45PM +0700, Whees Northbee wrote:
>> I'm really sorry if my post doesn't appropriate to the forum rule.. I
>> already asked in other forums 2 months ago, but no answer or had voted down
>> and closed..
> 
> It's not a matter about breaking some rule, but about you getting an 
> answer. Your question is very narrowly specific to a particular software 
> library. Of all the people here, YOU probably know more about it than 
> all the rest of us together.
> 
> Even though OpenCV *uses* Python, your question is not about Python. It 
> is about computer vision, and we know less than you about computer 
> vision.
> 
> 
> 
> -- 
> Steven
> 
> 
> --
> 
> Message: 3
> Date: Fri, 5 Sep 2014 10:41:03 -0700
> From: Marc Tompkins 
> To: Whees Northbee 
> Cc: "tutor@python.org" 
> Subject: Re: [Tutor] How to count vehicle? I'm trying but my code
>don'tincreasing..
> Message-ID:
>
> Content-Type: text/plain; charset=UTF-8
> 
>> On Fri, Sep 5, 2014 at 4:09 AM, Whees Northbee  wrote:
>> I'm really sorry if my post doesn't appropriate to the forum rule.. I
>> already asked in other forums 2 months a

[Tutor] private help...interacting with stderr/stdout

2014-09-02 Thread Crush
It is becoming too difficult to explain the problems I am having with my code 
via email. Is anyone willing to help via Skype or Teamviewer...I will pay for 
your time if need be. 

Thanks, 

Bo 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interacting with stderr

2014-08-31 Thread Crush
Alan said, 

"... you are reassigning p in the middle of a loop that 
depends on p. That's usually not a good idea..."

If not what I changed my code to, then I reckon I do not understand what he is 
suggesting I do. 

I have to reparse stderr, each time test_loop.sh is executed the content of 
stderr is different i.e. frames, bitrate, time running, etc. Picture, stderr 
out is being printed to the screen as a running log while the machine is 
decoding. The frames, time, etc. are counting up. If it has been decoding for 3 
days, the the frames, time, etc. will reflect this. 

As far as killing off every avconv and bmdplay process, that is exactly what I 
need to do if they exist before I execute test_loop. I need a "clean slate" 
so-to-speak before each execution. 

Again, my code works so far in the lab, but I havent tested it with a live 
broadcast yet. I figured it would not work the same while testing live and I 
was anticipating changes would need to be made like what you suggested...

"This function won't work as you intend. Specificly, the "if" test is wrong. 
You want to change:
if proc.name == process1 and process2:
if proc.name in (process1, process2):"

Psutil.Popen works just fine. And I will remove "out, err = p.communicate()" as 
you are are correct, it is not being used. 

Yes the rest of my code does in fact work fine. Would you be willing to 
Teamviewer into my machine, so you can see a healthy decoding? This would give 
you a better understanding of what I am trying to accomplish. 

Thank you, 

Bo

>> On Aug 31, 2014, at 1:22 AM, Cameron Simpson  wrote:
>> 
>> On 30Aug2014 22:32, Crush  wrote:
>> Thank you Allan for your criticism. Please see the below changes. As far as 
>> the embedded loops, I know no other way to achieve the same out come.
> 
> Regrettably I've lost Alan's email on that (I had it:-).
> 
> It looks like you've taken he concern over nested use of p.stderr too 
> literally. It loops like you avoid using the same stderr by restarting 
> "test_loop.sh" in the inner loops and reparsing their error outputs. I'm 
> fairly sure that is not what Alan intended and also not what you want to be 
> doing.  Please explain your thinking here.
> 
> Regarding nested loops on the same iterable:
> 
> It is ok to nested use of an iterator, with some caution. The typical use 
> case is some sort of nesting parse of the output. For example, if you were 
> looking for the word "Segmentation", and then intending to act specially on 
> all following lines until some marker. Another gleaming example that springs 
> to mind would be gathering up python stack traces (multiline outputs) in some 
> error log.
> 
> You'd fairly naturally end up with code a bit like this:
> 
> for line in p.stderr:
>   if "Segemntation" in line:
> # ok, found the start line
> for inner_line in p.stderr:
>   if "end segemntation marker" in inner_line:
> break
>   ... do something with inner_line
> 
> That essentially has the effect that all the lines from "Segmentation" to 
> "end segemntation marker" are processed specially by the inner loop, and 
> after you see the end marker you return to the outer loop, looking for the 
> next occurence of "Segmentation".
> 
> There is really only one pitfall with this, and that is the possibility that 
> the end marker line is itself important.
> 
> Imagine you had two inner loops, one for the "Segmentation" section and 
> another to handle some other section, like this:
> 
> for line in p.stderr:
>   if "Segemntation" in line:
> # ok, found the start line
> ... do the "Segmentation" section ...
>   elif "other-section" in line:
> # ok, found the start line
> ... do the "other-section" section ...
>   else:
> # boring line, report it or discard it etc
> 
> Simple and straight forward, yes? It will nicely handly input like this:
> 
>  blah
>  blah
>  begin Segmentation
>>> stuff
>>> more stuff
>  end segmentation marker
>  blah
>  blah
>  begin other-section
>>> other stuff
>>> even more other stuff
>  end the other section
>  blah
> 
> However, consider the case where the end marker for the "Segmentation" 
> section is not some special line generated by the "Segmentation" event, but 
> simply some line that is not a match. Like the beginning of an 
> "other-section" section. Eg:
> 
>  blah
>  blah
>  begin Segmentation
>>> stuff
>>> more stuff
>  begin other-section
>>> other stuff
>>> even more

Re: [Tutor] Tutor Digest, Vol 126, Issue 86

2014-08-30 Thread Crush
Thank you Allan for your criticism. Please see the below changes. As far as the 
embedded loops, I know no other way to achieve the same out come. 

def kill_proc(process1, process2):
   i = psutil.Popen(["ps", "cax"], stdout=PIPE)
   out, err = i.communicate()
   for proc in psutil.process_iter():
   if proc.name == process1 and process2:
   proc.kill()

while True:
   while count < 15:
   count += 1
   kill_proc("bmdplay", "avconv")
   print "Starting the script", count
   time.sleep(2)
   p = subprocess.Popen("/Downloads/bmdtools/test_loop.sh",
shell=True, stderr=PIPE)
   for line in p.stderr:
   print line
   if "Segmentation" in line:
   kill_proc("bmdplay", "avconv")
   while restart < 3:
   restart += 1
   time.sleep(2)
   q =
subprocess.Popen("/Downloads/bmdtools/test_loop.sh", shell=True,
stderr=PIPE)
   for line in q.stderr:
   print line
   if restart == 3:
   # send email saying so
   sys.exit()
   if "storing 0x" in line:
   kill_proc("bmdplay", "avconv")
   while restart < 3:
   restart += 1
   sleep.time(2)
   r =
subprocess.Popen("/Downloads/bmdtools/test_loop.sh", shell=True,
stderr=PIPE)
   for line in r.stderr:
   print line
   if restart == 3:
   # send email saying so
   sys.exit()
   if count == 10:
   print "Going to sleep, will try again in..."
   #send email saying so
   time.sleep(2)
   if count == 15:
   # send email saying so
   print "Gave up"
   break
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interacting with stderr

2014-08-30 Thread Crush
Ok, i understand the dangers of using root. I will bring this to the attention 
of the CTO of the company, which he should know already, but none the less. You 
must know though, I do not have the power to change the way things are done. If 
he says "ahhh, dont worry about it," then what am I to do? Personally, I use 
Ubuntu, which I really like, and I dont have to worry about the "su/root" 
issuethe companies encoders and decoders, now thats a whole other issue. 

Now, enough scolding me :)

Bo 

On Aug 30, 2014, at 8:09 PM, Danny Yoo  wrote:

 One other thing: if you can avoid running commands as root, I'd
 strongly suggest doing so.  Your second screenshot shows that you're
 running as root superuser, and the imaginary security demon that sits
 on my left shoulder is laughing uproariously as we speak.
>>> 
>>> Haha Yes I am aware of people like you who are just itching to exploit
>>> vulnerabilities like that; however, the programs my company uses to
>>> broadcast will only run as root.
>> 
>> 
>> That's a really bad design decision, and rarely necessary. It is often
>> _easy_, but it leaves your systems at much greater risk.
> 
> 
> I agree with Cameron.  On a scale from 1 to 10, where 10 is "oh my god
> this is bad", what you're doing by running such a program as root is
> about an 8 or 9.  But, then, I've always been an optimist.
> 
> The fact that you're doing this in the context of a company, where
> things actually _matter_,  turns the situation from what I thought was
> merely "dubious" into one that's closer to "criminal".  Please, please
> get an education from your local friendly Unix system administrator
> about running as root superuser.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interacting with stderr

2014-08-29 Thread Crush
Haha Yes I am aware of people like you who are just itching to exploit 
vulnerabilities like that; however, the programs my company uses to broadcast 
will only run as root. 

Bo 

> On Aug 29, 2014, at 6:12 PM, Danny Yoo  wrote:
> 
> Hi Bo,
> 
> One other thing: if you can avoid running commands as root, I'd
> strongly suggest doing so.  Your second screenshot shows that you're
> running as root superuser, and the imaginary security demon that sits
> on my left shoulder is laughing uproariously as we speak.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interacting with stderr

2014-08-29 Thread Crush
Ok so no links to dropbox? Man im confused...i thought links to dropbox were ok?

Wow i feel like such an idiot haha. I should have caught that capitolization 
error! 

Im sorry to have waisted your time.

Bo 

> On Aug 29, 2014, at 6:06 PM, Danny Yoo  wrote:
> 
>> On Fri, Aug 29, 2014 at 2:13 PM, Crush  wrote:
>> I am now able to print stderr to the screen, however I still can not run
>> conditional statements against stderr.
>> 
>> Please see the screenshots(SS) here...
>> 
>> https://www.dropbox.com/sh/31wyjtvqymo94uk/AAAZaxwB27nw1nmz7tz69I5La?dl=0
> 
> 
> Hi Bo,
> 
> 
> Consider case sensitivity.
> 
> 
>>>> "a" == "A"
> False
> 
> 
> 
> Also, in the screenshots you're presenting, you very much should want
> to do a copy-and-paste of the text content and include it in your
> question text.  The reason is because, for all the Tutor folks who
> aren't in a GUI right now, they can't see your program.
> 
> 
> For the sake of the others on the list: your first screenshot has the 
> following:
> 
> 
> ##
> for line in p.stderr:
>print line
>if "segmentation" in line:
>print "Yes it is"
>...
> ###
> 
> 
> and your second screenshot has the content:
> 
> 
> ##
> ...
>  11265 Segmentation fault   | ./bmdplay -m 12 -f pipe:0
> 
> Gave up
> ##
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interacting with stderr

2014-08-29 Thread Crush
I am now able to print stderr to the screen, however I still can not run 
conditional statements against stderr. 

Please see the screenshots(SS) here...

https://www.dropbox.com/sh/31wyjtvqymo94uk/AAAZaxwB27nw1nmz7tz69I5La?dl=0

Bo 

> On Aug 28, 2014, at 6:12 PM, Cameron Simpson  wrote:
> 
>> On 28Aug2014 09:42, Crush  wrote:
>> As far as the pipe in...
>> 
>> "avconv -v verbose -re -analyzeduration 1000 
>> -ihttp://localhost:6498/ms2/1382097438004/0MediaPlayer+0+/octoshape+hVV+octolive.americaone.com+V+aone+V+live+V+ONECONNXTDEMO1_HD_flv/aoneliveONECONNXTDEMO1HDflv
>>  -c:v rawvideo -c:a pcm_s16le -ar 48000 -f nut - | ./bmdplay -m 12 -f pipe:0"
>> 
>> ...it has to be there.
> 
> Indeed. We're not arguing about that. Leave it there for.
> 
>> Currently, i am running a shell script that is handling this decoding 
>> process i.e. the real long avconv/bmdplay command. So you are saying leave 
>> the shell script and invoke it from a python script...something like "p = 
>> subprocess.Popen("./my_script.sh")? How will the above allow me to interact 
>> with stderr in oppose to running the avconv/bmdplay command directly in 
>> python?
> 
> No, we're no saying that.
> 
> You could (and presumably do) have this long incantation in your shell 
> script.  As far as the Python stuff goes, that does not change anything: you 
> can invoke your shell script or invoke your long command directly. Either way 
> you need to grab the stderr on the fly and work with it.
> 
> Personally, I would keep the pipeline in the shell script where it is easier 
> to edit and invoke the script from Python (easier to read). Your call.
> 
>> As far as not using "shell=True," if I dont have it set to True, the 
>> terminal hangs and will not display stderr to the screen as it is currently 
>> does.
> 
> Let's tackle shell=True later.
> 
> What you need to do is examine stderr before the shell script/pipeline is 
> complete, and for that you need to separate starting the process, reading 
> stderr, and waiting for process completion into distinct parts, which was 
> what my example code was doing. I'll recite it again here:
> 
>  from subprocess import Popen, PIPE
> 
>  P = Popen("avconv ... lots of arguments...", shell=True, stderr=PIPE)
> 
>  for line in P.stderr:
>  ... examine the line from stderr ...
> 
>  # ok, we have read all of stderr now
>  xit = P.wait()
>  if xit != 0:
>  ... command was unsuccessful, complain, maybe abort ...
> 
> Please try adapting your Python code to that and see where you end up.
> Put a print statement as the first line in the for-loop so you can see if you 
> are receiving stderr lines as intended.
> 
> Cheers,
> Cameron Simpson 
> 
> As soon as we started programming, we found to our surprise that it wasn't as
> easy to get programs right as we had thought. Debugging had to be discovered.
> I can remember the exact instant when I realized that a large part of my life
> from then on was going to be spent in finding mistakes in my own programs.
>- Maurice Wilkes discovers debugging, 1949
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Quick question for Tutor admin.

2014-08-28 Thread Crush
Am I allowed to attach screen shots to my emails?

Bo 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interacting with stderr

2014-08-28 Thread Crush
So, are yall done arguing haha...jk! Seriously, thank you for taking the time 
to pick this issue apart with me. Cameron your "learning" comment was right on; 
my ultimate goal in posting here is to learn and of course to figure out my 
code. 

As far as the pipe in...

"avconv -v verbose -re -analyzeduration 1000 
-ihttp://localhost:6498/ms2/1382097438004/0MediaPlayer+0+/octoshape+hVV+octolive.americaone.com+V+aone+V+live+V+ONECONNXTDEMO1_HD_flv/aoneliveONECONNXTDEMO1HDflv
 -c:v rawvideo -c:a pcm_s16le -ar 48000 -f nut - | ./bmdplay -m 12 -f pipe:0"

...it has to be there. Currently, i am running a shell script that is handling 
this decoding process i.e. the real long avconv/bmdplay command. So you are 
saying leave the shell script and invoke it from a python script...something 
like "p = subprocess.Popen("./my_script.sh")? How will the above allow me to 
interact with stderr in oppose to running the avconv/bmdplay command directly 
in python? 

As far as not using "shell=True," if I dont have it set to True, the terminal 
hangs and will not display stderr to the screen as it is currently does. 

Bo 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Interacting with stderr

2014-08-27 Thread Crush
As far as sending the contents of stderr to a tmp file...hmmm, i will try that. 
My only concern is, many of these systems run live demo feeds for many 
days...10+. Im afraid the file will fill up very quickly and present problems. 

Stderr=PIPE causes the terminal to hang. I can not wait for the process to 
terminate, i need to read stderr as it is being fed data.. Would fifos be of 
any use here? 

I will research the tempfile module.

Bo 

> On Aug 27, 2014, at 7:38 PM, tutor-requ...@python.org wrote:
> 
> Send Tutor mailing list submissions to
>tutor@python.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>tutor-requ...@python.org
> 
> You can reach the person managing the list at
>tutor-ow...@python.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> 
> 
> Today's Topics:
> 
>   1. Re: Python Programming (Alan Gauld)
>   2. Re: simple unicode question (Alan Gauld)
>   3. Interacting with stderr (Crush)
>   4. Re: Interacting with stderr (Cameron Simpson)
>   5. Re: debug and execute python code in Mac (Alan Gauld)
>   6. Re: Interacting with stderr (Alan Gauld)
> 
> 
> --
> 
> Message: 1
> Date: Wed, 27 Aug 2014 19:57:12 +0100
> From: Alan Gauld 
> To: tutor@python.org
> Subject: Re: [Tutor] Python Programming
> Message-ID: 
> Content-Type: text/plain; charset=windows-1252; format=flowed
> 
>> On 27/08/14 14:40, Jake wrote:
>> To whom it may concern,
>> My name is Jake and I have recently started the GCSE computing course with 
>> school.
> 
>> answera = input()
>> if answera == ["Oslo" or "oslo"]:
> 
> This doesn't do what you think it does.
> 
> ["Oslo" or "oslo"]  is a list
> 
> "Oslo" or "oslo"   is the content of the list and
> is a boolean expression which evaluates to True.
> (Each non-empty string is considered True by Python)
> 
> So your 'if' line looks to Python like:
> 
> if answera == [True]:
> 
> But answera is a string so it will never equal a list
> with a single boolean value so you go to the else
> clause.
> 
> A better way to do what you want is to convert the input
> to lowercase using the string lower() method and compare
> that to the string you want, like so:
> 
> if answera.lower() == "oslo":
> 
> If you need to check multiple possible answers you can use
> a list of strings and the 'in' operator like this:
> 
> if answera.lower() in ['amsterdam', 'london', 'oslo']:
> 
> HTH
> -- 
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
> 
> 
> 
> --
> 
> Message: 2
> Date: Wed, 27 Aug 2014 20:09:36 +0100
> From: Alan Gauld 
> To: tutor@python.org
> Subject: Re: [Tutor] simple unicode question
> Message-ID: 
> Content-Type: text/plain; charset=utf-8; format=flowed
> 
> On 27/08/14 15:57, Albert-Jan Roskam wrote:
> 
>>> if *fewer* than 1 in 10 operations will raise an exception, then use
>>> try...except; but if *more* than 1 in 10 operations will raise an
>>> exception, and it is safe to do so, then LBYL may be appropriate.
>> 
>> 
>> Thanks a lot, Steven! This kind of stuff should be in a book.
> 
> It is in lots of books but they aren't Python books; they are generic 
> software engineering books. Because this is not really a language 
> specific type design issue, its general software design.
> 
>> Do you know of any real life examples where the code is written
>> in such a way that it could switch from AFTP to LBYL
> 
> It would be very unlikely since it would almost always be a case of 
> premature optimisation. You would need to be inside a very tight loop to 
> make that kind of optimisation worthwhile in real world scenarios.
> (And the cost of evaluating it would probably outweigh any gains.)
> 
> Much more important is to make the code correct and maintainable than to 
> worry about slight performance issues before they are a proven issue.
> Building those kind of self modifying control flows makes code much more 
> error prone and difficult to modify.
> 
> The vast majority of performance issues in software are to do with 
> blockages in IO processing(network, disk access, human input, etc)
> or database processing (big data or complex sear

[Tutor] Interacting with stderr

2014-08-27 Thread Crush
Hello, it has been a while and I hope I am sending to the correct email. 

How would I go about running a conditional statement against the contents of 
stderr. For instance, if "blah blah blah" is in stderr do X, else do Y. 

CODE: SELECT ALL
 
#!/usr/bin/env python
import subprocess
from subprocess import PIPE
i = 0
while i < 10:
p = subprocess.call("avconv -v verbose -re -analyzeduration 1000 -i 
http://localhost:6498/ms2/1382097438004/0MediaPlayer+0+/octoshape+hVV+octolive.americaone.com+V+aone+V+live+V+ONECONNXT_DEMO1_HD_flv/aoneliveONECONNXTDEMO1HDflv
  -c:v rawvideo -c:a pcm_s16le -ar 48000 -f nut - | ./bmdplay -m 12 -f pipe:0", 
shell=True)
i += 1
if i == 10:
print "Gave up"


The above code works and I get no tracebacks, however I need to add to it and 
check the contents of stderr. Avconv by default sends the audio and video to 
stdout, which then sends the signal to a capture card in the machine. Avconv is 
sending the status of the broadcasted signal i.e. frames, time, fps, etc. to 
stderr, which is displayed in the terminal. 

Bo ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor