今天在试验>上的例程,发现了一个小问题,列举如下: 下面是创建的一个类 #! /usr/bin/python # FileName: time1.py # Description: Simple definition of class Time # Author: yk # Date: Sat May 17 04:07:34 CST 2008 class Time: """Time abstract definition of class Time.""" def __init__( self ): """Initializes hour,minute and second to zero""" self.hour = 0 ...
by yk325 - Python文档中心 - 2008-05-16 21:36:12 阅读(1469) 回复(0)
try: except Except,e: 如果有异常就返回为false 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/84280/showart_2048668.html
shell 脚本 例如sed -n '/send CISMAPSubscribeServiceRsp/,/}/p' ./log/run/cmanager*.log |awk -v RS='}' '{if (/msg:CISMAPSubscribeServiceRsp/ && /serviceId = \[125000000000000009051\]/ && /msIsdn = \[8612311111111\]/) print $0"}"}' | grep -w "result = " | awk ' { print $9}' 执行完成后 打印 第九列 结果如下 : [0] [0] 脚本命令 返回值 存入一个string 变量 strReturn中 我想把中间的数字 放入list...
我要用python写一个脚本,判断一个字符串中是否有某个字符串,如果有的话,则返回1, 没有的话返回0, 会有其他程序扑捉到返回值来进行其他的操作! 我的程序如下: import re stname='one string' if re.search('b', stname)==None: return 0 else: return 1 我把return 改为print都是可以正常运行的,但是用return 却不可以了 错误提示为: return 0 SyntaxError: 'return' outside function 请大家看看,我这个程序该怎么写...
麻烦各位大侠帮看看这个程序的返回值为啥不是零???谢谢!
#! /usr/bin/python
import re
import os
import sys
import gzip
def rmN(Args):
if not Args:
print 'Usage: rmN
请教各位大牛一个问题: python的os模块,在调用os.system()命令后,看python文档知道,返回的参数应该是该shell命令的返回值,正确为0,错误为非0 但是我发现如果该shell脚本的运行时间很长(脚本是正确的),调用os.system命令会直接返回一个非0参数,而我想用这个返回值做下一步的操作就执行不了了。 想请教各位大牛这种情况要如何解决啊,谢谢!
if( sign_weights.find("1110:") )!=-1:我想查找有这个字符串 但是这个有缺陷,如果有子串是111110:的这样也会匹配到。 有没有办法搜索以1110:开头的, 我试了前面加个^,但是好像不行
小弟是python新手,今天写了个脚本,运行的时候没有什么报错信息,但结果是没有成功的 #!/usr/bin/env python import string import re import paramiko import os import socket def file_fun(): log=open('/root/mss-python-log.txt','w') filentp="/etc/ntp.conf" try: f1=open(filentp,'r') except IOError,e: log.write('there is no ntp.conf file') allline1=f1.readlines() f1.close() #alllines...
python初学,下面的异常题请教是什么情况?
>>> def con(x,y):
result=x+y
return result
con(1,2)
SyntaxError: invalid syntax
>>> con
Traceback (most recent call last):
File "