[Tutor] why "ifconfig" is alway running?

2010-12-18 Thread lei yang
my script is

#!/usr/bin/env python
import datetime
import subprocess
import sys
import os
import signal
from time import sleep

def runForAWhile(cmd, secs=10):
  print("running %s" % cmd)
  timeout = datetime.timedelta(seconds=secs)
  print timeout
  proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True)
  status = proc.poll()
  start = datetime.datetime.now()
  while (status is None and (datetime.datetime.now() - start) <
timeout): #not timed out
  #print proc.stdout.readline() #TODO timestamp?
  print status
  #print datetime.datetime.now() - start
  if 0 == status:
  print("'%s' is program exited" %cmd)
  else:
  try:
  os.kill(proc.pid, signal.SIGINT)
  print "Process timeout: '%s'" % cmd
  except OSError:
  pass
cmd="ifconfig"
runForAWhile(cmd,10)

why it print many "None" in 10 second. which means "ifconfig" is
running in 10sec, why, what's wrong withi my script,
I just want to let my programe running, if it's timeout(10sec), kill it

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


Re: [Tutor] why "ifconfig" is alway running?

2010-12-18 Thread lei yang
#!/usr/bin/env python
import datetime
import subprocess
import sys
import os
import signal
from time import sleep

def runForAWhile(cmd, secs=10):
print("running %s" % cmd)
timeout = datetime.timedelta(seconds=secs)
print timeout
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True)
status = proc.poll()
start = datetime.datetime.now()
while (status is None and (datetime.datetime.now() - start) <
timeout): #not timed out
print proc.stdout.readline() #TODO timestamp?
#print status
#print datetime.datetime.now() - start
if 0 == status:
print("'%s' is program exited" %cmd)
else:
try:
os.kill(proc.pid, signal.SIGINT)
print "Process timeout: '%s'" % cmd
except OSError:
pass
cmd="ping 128.224.165.20 -c 4"
runForAWhile(cmd,30)


I see that "status" always "!=0“  why  program  is NOT exited

Lei



On Sun, Dec 19, 2010 at 1:15 AM, Alan Gauld  wrote:
>
> "lei yang"  wrote
>
>> def runForAWhile(cmd, secs=10):
>>   proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
>>
>> stderr=subprocess.STDOUT, shell=True)
>>   status = proc.poll()
>>   start = datetime.datetime.now()
>>   while (status is None and
>
>               (datetime.datetime.now() - start) <   timeout): #not timed out
>>
>>             print status
>>   if 0 == status:
>>     print("'%s' is program exited" %cmd)
>>  else:
>>     try:
>>         os.kill(proc.pid, signal.SIGINT)
>
>> why it print many "None" in 10 second. which means "ifconfig" is
>> running in 10sec, why, what's wrong withi my script,
>
> You only check the status once *before* entering the while loop.
> You need another status check inside the loop.
>
>> I just want to let my programe running, if it's timeout(10sec), kill it
>
> Its not clear from your mail if you have checked whether the
> process really is running - using the OS commands 'top' or 'ps'
> for example or whjether its just the None result you are concerned
> about. But try updating status first...
>
> HTH,
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] why "ifconfig" is alway running?

2010-12-19 Thread lei yang
On Sun, Dec 19, 2010 at 4:57 PM, Alan Gauld  wrote:
>
> "lei yang"  wrote
>
>
> def runForAWhile(cmd, secs=10):
>   print("running %s" % cmd)
>   timeout = datetime.timedelta(seconds=secs)
>   print timeout
>   proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> stderr=subprocess.STDOUT, shell=True)
>   status = proc.poll()
>
> You are still only checking status once outside the while loop.
>

Thanks, I make a stupid mistaking

Lei

>   start = datetime.datetime.now()
>   while (status is None and (datetime.datetime.now() - start) <
> timeout): #not timed out
>       print proc.stdout.readline() #TODO timestamp?
>       #print status
>       #print datetime.datetime.now() - start
>
>
>> I see that "status" always "!=0“  why  program  is NOT exited
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] why "ifconfig" is alway running?

2010-12-19 Thread lei yang
#!/usr/bin/env python
import datetime
import subprocess
import sys
import os
import signal
from time import sleep

def host_run(cmd, secs=10):
print("running %s" % cmd)
timeout = datetime.timedelta(seconds=secs)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True)
start = datetime.datetime.now()
while ( proc.poll() is None and (datetime.datetime.now() - start)
< timeout): #not timed out
print proc.stdout.readline() #TODO timestamp?
print "hello,i'm here"
sleep(1)
if 0 == proc.poll():
print("'%s' is program exited" %cmd)
else:
try:
os.kill(proc.pid, signal.SIGINT)
print "Process timeout: '%s'" % cmd
except OSError:
pass
#cmd="ping 128.114.122.2"
cmd="ssh r...@10.0.0.1"
host_run(cmd,10)

if cmd="ssh r...@10.0.0.1"
it never print "hello i'm here" , how can i handle this issue, and I
find my script cant process the "timeout" to kill it.
if cmd="ping 128.114.122.2", no this issue.

Lei

On Sun, Dec 19, 2010 at 4:57 PM, Alan Gauld  wrote:
>
> "lei yang"  wrote
>
>
> def runForAWhile(cmd, secs=10):
>   print("running %s" % cmd)
>   timeout = datetime.timedelta(seconds=secs)
>   print timeout
>   proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> stderr=subprocess.STDOUT, shell=True)
>   status = proc.poll()
>
> You are still only checking status once outside the while loop.
>
>   start = datetime.datetime.now()
>   while (status is None and (datetime.datetime.now() - start) <
> timeout): #not timed out
>       print proc.stdout.readline() #TODO timestamp?
>       #print status
>       #print datetime.datetime.now() - start
>
>
>> I see that "status" always "!=0“  why  program  is NOT exited
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] why "ifconfig" is alway running?

2010-12-19 Thread lei yang
On Sun, Dec 19, 2010 at 7:56 PM, Evert Rol  wrote:
>> #!/usr/bin/env python
>> import datetime
>> import subprocess
>> import sys
>> import os
>> import signal
>> from time import sleep
>>
>> def host_run(cmd, secs=10):
>>    print("running %s" % cmd)
>>    timeout = datetime.timedelta(seconds=secs)
>>    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
>> stderr=subprocess.STDOUT, shell=True)
>>    start = datetime.datetime.now()
>>    while ( proc.poll() is None and (datetime.datetime.now() - start)
>> < timeout): #not timed out
>>        print proc.stdout.readline() #TODO timestamp?
>>        print "hello,i'm here"
>>        sleep(1)
>>    if 0 == proc.poll():
>>        print("'%s' is program exited" %cmd)
>>    else:
>>        try:
>>            os.kill(proc.pid, signal.SIGINT)
>>           print "Process timeout: '%s'" % cmd
>>        except OSError:
>>            pass
>> #cmd="ping 128.114.122.2"
>> cmd="ssh r...@10.0.0.1"
>> host_run(cmd,10)
>>
>> if cmd="ssh r...@10.0.0.1"
>> it never print "hello i'm here" , how can i handle this issue, and I
>> find my script cant process the "timeout" to kill it.
>> if cmd="ping 128.114.122.2", no this issue.
>
> Have you tried running these two commands from the command line?
> Spot the difference: ssh is waiting for input (a password. And if 
> passwordless, it may still not produce output to stdout), while ping just 
> continues to produce output.
> Then look at the line
>    print proc.stdout.readline()
> Will that ever read a full line for the ssh command? Probably not, while for 
> ping it will.
>

it's a test, actually, I can't access 10.0.0.1, i just want to kill it
if *no responding" in 10 second, but it doesn't kill it. I don't know
why.
my script is to run a cmd, if more than 10 sec, kill it
can you show me where is wrong, thanks in advance

Lei


> So my guess is, your script gets stuck at that line.
> But if you ctrl-C to stop the script, you should see where your program gets 
> stuck. You didn't say where it got stuck, that would have helped.
>
> Good luck,
>
>  Evert
>
>
>> On Sun, Dec 19, 2010 at 4:57 PM, Alan Gauld  
>> wrote:
>>>
>>> "lei yang"  wrote
>>>
>>>
>>> def runForAWhile(cmd, secs=10):
>>>   print("running %s" % cmd)
>>>   timeout = datetime.timedelta(seconds=secs)
>>>   print timeout
>>>   proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
>>> stderr=subprocess.STDOUT, shell=True)
>>>   status = proc.poll()
>>>
>>> You are still only checking status once outside the while loop.
>>>
>>>   start = datetime.datetime.now()
>>>   while (status is None and (datetime.datetime.now() - start) <
>>> timeout): #not timed out
>>>       print proc.stdout.readline() #TODO timestamp?
>>>       #print status
>>>       #print datetime.datetime.now() - start
>>>
>>>
>>>> I see that "status" always "!=0“  why  program  is NOT exited
>>>
>>>
>>> --
>>> Alan Gauld
>>> Author of the Learn to Program web site
>>> http://www.alan-g.me.uk/
>>>
>>>
>>> ___
>>> Tutor maillist  -  tu...@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] why "ifconfig" is alway running?

2010-12-19 Thread lei yang
On Sun, Dec 19, 2010 at 8:09 PM, Evert Rol  wrote:
>>>> #!/usr/bin/env python
>>>> import datetime
>>>> import subprocess
>>>> import sys
>>>> import os
>>>> import signal
>>>> from time import sleep
>>>>
>>>> def host_run(cmd, secs=10):
>>>>    print("running %s" % cmd)
>>>>    timeout = datetime.timedelta(seconds=secs)
>>>>    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
>>>> stderr=subprocess.STDOUT, shell=True)
>>>>    start = datetime.datetime.now()
>>>>    while ( proc.poll() is None and (datetime.datetime.now() - start)
>>>> < timeout): #not timed out
>>>>        print proc.stdout.readline() #TODO timestamp?
>>>>        print "hello,i'm here"
>>>>        sleep(1)
>>>>    if 0 == proc.poll():
>>>>        print("'%s' is program exited" %cmd)
>>>>    else:
>>>>        try:
>>>>            os.kill(proc.pid, signal.SIGINT)
>>>>           print "Process timeout: '%s'" % cmd
>>>>        except OSError:
>>>>            pass
>>>> #cmd="ping 128.114.122.2"
>>>> cmd="ssh r...@10.0.0.1"
>>>> host_run(cmd,10)
>>>>
>>>> if cmd="ssh r...@10.0.0.1"
>>>> it never print "hello i'm here" , how can i handle this issue, and I
>>>> find my script cant process the "timeout" to kill it.
>>>> if cmd="ping 128.114.122.2", no this issue.
>>>
>>> Have you tried running these two commands from the command line?
>>> Spot the difference: ssh is waiting for input (a password. And if 
>>> passwordless, it may still not produce output to stdout), while ping just 
>>> continues to produce output.
>>> Then look at the line
>>>    print proc.stdout.readline()
>>> Will that ever read a full line for the ssh command? Probably not, while 
>>> for ping it will.
>>>
>>
>> it's a test, actually, I can't access 10.0.0.1, i just want to kill it
>> if *no responding" in 10 second, but it doesn't kill it. I don't know
>> why.
>> my script is to run a cmd, if more than 10 sec, kill it
>> can you show me where is wrong, thanks in advance
>
> But you never said where the script gets stuck. That would be a very 
> important first step for debugging.
>
> And if I run this script, I get the following:
> "
> $> python bla.py
> running ssh r...@10.0.0.1
> ssh: connect to host 10.0.0.1 port 22: Connection refused
>
> hello,i'm here
> "
> So seems to work for me.
> thus, what is the result of
> $> ssh r...@10.0.0.1
> for you?
>

[lya...@pek-lpgbuild13 py]$ ssh r...@10.0.0.1
ssh: connect to host 10.0.0.1 port 22: Connection timed out

but it will wait for above 30 seconds then print "ssh: connect to host
10.0.0.1 port 22: Connection timed out", but my script is designed to
kill it if cmd running more than 10 secs.


Lei

>  Evert
>
>
>>> So my guess is, your script gets stuck at that line.
>>> But if you ctrl-C to stop the script, you should see where your program 
>>> gets stuck. You didn't say where it got stuck, that would have helped.
>>>
>>> Good luck,
>>>
>>>  Evert
>>>
>>>
>>>> On Sun, Dec 19, 2010 at 4:57 PM, Alan Gauld  
>>>> wrote:
>>>>>
>>>>> "lei yang"  wrote
>>>>>
>>>>>
>>>>> def runForAWhile(cmd, secs=10):
>>>>>   print("running %s" % cmd)
>>>>>   timeout = datetime.timedelta(seconds=secs)
>>>>>   print timeout
>>>>>   proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
>>>>> stderr=subprocess.STDOUT, shell=True)
>>>>>   status = proc.poll()
>>>>>
>>>>> You are still only checking status once outside the while loop.
>>>>>
>>>>>   start = datetime.datetime.now()
>>>>>   while (status is None and (datetime.datetime.now() - start) <
>>>>> timeout): #not timed out
>>>>>       print proc.stdout.readline() #TODO timestamp?
>>>>>       #print status
>>>>>       #print datetime.datetime.now() - start
>>>>>
>>>>>
>>>>>> I see that "status" always "!=0“  why  program  is NOT exited
>>>>>
>>>>>
>>>>> --
>>>>> Alan Gauld
>>>>> Author of the Learn to Program web site
>>>>> http://www.alan-g.me.uk/
>>>>>
>>>>>
>>>>> ___
>>>>> Tutor maillist  -  tu...@python.org
>>>>> To unsubscribe or change subscription options:
>>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>>
>>>> ___
>>>> Tutor maillist  -  tu...@python.org
>>>> To unsubscribe or change subscription options:
>>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] why "ifconfig" is alway running?

2010-12-19 Thread lei yang
On Sun, Dec 19, 2010 at 8:29 PM, Evert Rol  wrote:
>>>>>> #!/usr/bin/env python
>>>>>> import datetime
>>>>>> import subprocess
>>>>>> import sys
>>>>>> import os
>>>>>> import signal
>>>>>> from time import sleep
>>>>>>
>>>>>> def host_run(cmd, secs=10):
>>>>>>    print("running %s" % cmd)
>>>>>>    timeout = datetime.timedelta(seconds=secs)
>>>>>>    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
>>>>>> stderr=subprocess.STDOUT, shell=True)
>>>>>>    start = datetime.datetime.now()
>>>>>>    while ( proc.poll() is None and (datetime.datetime.now() - start)
>>>>>> < timeout): #not timed out
>>>>>>        print proc.stdout.readline() #TODO timestamp?
>>>>>>        print "hello,i'm here"
>>>>>>        sleep(1)
>>>>>>    if 0 == proc.poll():
>>>>>>        print("'%s' is program exited" %cmd)
>>>>>>    else:
>>>>>>        try:
>>>>>>            os.kill(proc.pid, signal.SIGINT)
>>>>>>           print "Process timeout: '%s'" % cmd
>>>>>>        except OSError:
>>>>>>            pass
>>>>>> #cmd="ping 128.114.122.2"
>>>>>> cmd="ssh r...@10.0.0.1"
>>>>>> host_run(cmd,10)
>>>>>>
>>>>>> if cmd="ssh r...@10.0.0.1"
>>>>>> it never print "hello i'm here" , how can i handle this issue, and I
>>>>>> find my script cant process the "timeout" to kill it.
>>>>>> if cmd="ping 128.114.122.2", no this issue.
>>>>>
>>>>> Have you tried running these two commands from the command line?
>>>>> Spot the difference: ssh is waiting for input (a password. And if 
>>>>> passwordless, it may still not produce output to stdout), while ping just 
>>>>> continues to produce output.
>>>>> Then look at the line
>>>>>    print proc.stdout.readline()
>>>>> Will that ever read a full line for the ssh command? Probably not, while 
>>>>> for ping it will.
>>>>>
>>>>
>>>> it's a test, actually, I can't access 10.0.0.1, i just want to kill it
>>>> if *no responding" in 10 second, but it doesn't kill it. I don't know
>>>> why.
>>>> my script is to run a cmd, if more than 10 sec, kill it
>>>> can you show me where is wrong, thanks in advance
>>>
>>> But you never said where the script gets stuck. That would be a very 
>>> important first step for debugging.
>>>
>>> And if I run this script, I get the following:
>>> "
>>> $> python bla.py
>>> running ssh r...@10.0.0.1
>>> ssh: connect to host 10.0.0.1 port 22: Connection refused
>>>
>>> hello,i'm here
>>> "
>>> So seems to work for me.
>>> thus, what is the result of
>>> $> ssh r...@10.0.0.1
>>> for you?
>>>
>>
>> [lya...@pek-lpgbuild13 py]$ ssh r...@10.0.0.1
>> ssh: connect to host 10.0.0.1 port 22: Connection timed out
>>
>> but it will wait for above 30 seconds then print "ssh: connect to host
>> 10.0.0.1 port 22: Connection timed out", but my script is designed to
>> kill it if cmd running more than 10 secs.
>
> So it doesn't produce output for at least 30 secs. Then my guess that it gets 
> stuck at the readline() line still stands.


Right, it gets stuck at the readline(), is there a function not get
stuck to instead of readline().

Lei


> Unfortunately, you still haven't told us where the script gets stuck.
> Also, have you tried to let the script run for, say, 30 seconds at least? Ie, 
> the time it takes for the ssh command to time out by itself.
>
>  Evert
>
>
>>
>>
>> Lei
>>
>>>  Evert
>>>
>>>
>>>>> So my guess is, your script gets stuck at that line.
>>>>> But if you ctrl-C to stop the script, you should see where your program 
>>>>> gets stuck. You didn't say where it got stuck, that would have helped.
>>>>>
>>>>> Good luck,
>>>>>
>>>>>  Evert
>>>

Re: [Tutor] why "ifconfig" is alway running?

2010-12-19 Thread lei yang
On Sun, Dec 19, 2010 at 9:05 PM, Sander Sweers  wrote:
> On 19 December 2010 13:43, lei yang  wrote:
>> Right, it gets stuck at the readline(), is there a function not get
>> stuck to instead of readline().
>
> readline() will keep reading stdout until it received a newline
> character. So if there is nothing to read it will wait forever. The
> solution is to wait with reading until there is actually something to
> read. And it is recommended [1] to use proc.communicate() instead of
> reading directly from stdout.
>
> Also you should use proc.terminate() or proc.kill() to stop the command.
>
> Below is a modified version of your function to show what I mean.
>
> [1] http://docs.python.org/library/subprocess.html#subprocess.Popen.stdin
>

Thanks very much, that's really what I want

Lei

> Greets
> Sander
>
> def host_run(cmd, secs=10):
>    print("running %s" % cmd)
>    timeout = datetime.timedelta(seconds=secs)
>    proc = subprocess.Popen(
>        cmd,
>        stdout=subprocess.PIPE,
>        stderr=subprocess.STDOUT,
>        shell=True)
>    start = datetime.datetime.now()
>    while ( proc.poll() is None and (datetime.datetime.now() - start)
> < timeout): #not timed out
>        print "hello,i'm here"
>        sleep(1)
>    if 0 == proc.poll():
>        stdout, stderr = proc.communicate() #get stdout and stderr
>        print("'%s' is program exited" %cmd)
>        print stdout
>        print stderr
>    else:
>        proc.terminate() #Can use proc.kill() as well
>        stdout, stderr = proc.communicate() #get stdout and stderr
>        print 'Timeout: Process terminated'
>        print stdout
>        print stderr
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] why "ifconfig" is alway running?

2010-12-20 Thread lei yang
On Sun, Dec 19, 2010 at 9:05 PM, Sander Sweers  wrote:
> On 19 December 2010 13:43, lei yang  wrote:
>> Right, it gets stuck at the readline(), is there a function not get
>> stuck to instead of readline().
>
> readline() will keep reading stdout until it received a newline
> character. So if there is nothing to read it will wait forever. The
> solution is to wait with reading until there is actually something to
> read. And it is recommended [1] to use proc.communicate() instead of
> reading directly from stdout.
>
> Also you should use proc.terminate() or proc.kill() to stop the command.
>
> Below is a modified version of your function to show what I mean.
>
> [1] http://docs.python.org/library/subprocess.html#subprocess.Popen.stdin
>
> Greets
> Sander
>
> def host_run(cmd, secs=10):
>    print("running %s" % cmd)
>    timeout = datetime.timedelta(seconds=secs)
>    proc = subprocess.Popen(
>        cmd,
>        stdout=subprocess.PIPE,
>        stderr=subprocess.STDOUT,
>        shell=True)
>    start = datetime.datetime.now()
>    while ( proc.poll() is None and (datetime.datetime.now() - start)
> < timeout): #not timed out
>        print "hello,i'm here"
>        sleep(1)
>    if 0 == proc.poll():
>        stdout, stderr = proc.communicate() #get stdout and stderr
>        print("'%s' is program exited" %cmd)
>        print stdout
>        print stderr
>    else:
>        proc.terminate() #Can use proc.kill() as well

my python verison is 2.5, so has no kill or terminate attribute, so I still use
os.kill(proc.pid, signal.SIGINT) instead

>        stdout, stderr = proc.communicate() #get stdout and stderr


 and I find it will get stuck here

>        print 'Timeout: Process terminated'
>        print stdout
>        print stderr
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] what's wrong with this ?

2015-04-21 Thread lei yang
>>>start_time = "2014-7-1"
>>> revlines = commands.getoutput("git log --pretty=format:'%ad:%an'
--date=short --since='%s' --no-merges" %start_time).strip().split('\n')
Traceback (most recent call last):
  File "", line 1, in 
ValueError: unsupported format character 'a' (0x61) at index 26
>>>


if I directly use

revlines = commands.getoutput("git log --pretty=format:'%ad:%an'
--date=short --since='2014-7-1' --no-merges" ).strip().split('\n')

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


[Tutor] help about to how many times the function called

2013-01-04 Thread lei yang
Hi experts

I have a function will print PASS status



def print_pass(t_elapsed):
"""
Print PASS to stdout with PASS (green) color.
"""
print_stdout(bcolors.PASS + "PASS" + bcolors.ENDC + " (%.2f s)" % t_elapsed)

I want to calculate the pass number, so I want to get " how many times
this function called"

any help?

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


[Tutor] how to send "ctrl+a+c" with python

2014-01-22 Thread lei yang
Hi expert,

I want to use pexpect to send "ctrl+a+c"
how should I do?

self.vm_session.sendline("")

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


Re: [Tutor] how to send "ctrl+a+c" with python

2014-01-22 Thread lei yang
thanks, it works for me

Lei



On Wed, Jan 22, 2014 at 10:35 PM, eryksun  wrote:

> On Wed, Jan 22, 2014 at 8:49 AM, lei yang  wrote:
> >
> > I want to use pexpect to send "ctrl+a+c"
>
> What's ctrl+a+c? If this is for screen, then I think you mean ctrl+a c:
>
> sendcontrol('a')
> send('c')
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] how to express shift+enter in python

2014-09-28 Thread lei yang
Hi expert,

How to express shift+enter in python ?

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


Re: [Tutor] how to express shift+enter in python

2014-09-28 Thread lei yang
Hi Chris,

I just use "xlwt" lib to newline in one cell, I find it display with one
line in windows but works in linux, so I guess it maybe"shift+enter" to
newline

Lei


On Sun, Sep 28, 2014 at 11:04 PM, Chris “Kwpolska” Warrick <
kwpol...@gmail.com> wrote:

> On Sun, Sep 28, 2014 at 4:53 PM, lei yang  wrote:
> > Hi expert,
> >
> > How to express shift+enter in python ?
> >
> > Thanks
>
> What do you want to express, exactly?  This key combination can have
> multiple meanings and ways to achieve it, depending on your needs.  Do
> you want to send the key combination to an app?  What is it, exactly,
> that you want to do?  What app uses Shift+Enter in the way you want to
> use it?
>
> --
> Chris “Kwpolska” Warrick <http://chriswarrick.com/>
> PGP: 5EAAEA16
> stop html mail | always bottom-post | only UTF-8 makes sense
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor