ChinaUnix.net
相关文章推荐:

python 函数返回值

今天在试验>上的例程,发现了一个小问题,列举如下: 下面是创建的一个类 #! /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

by hkebao - Python文档中心 - 2009-09-09 08:42:40 阅读(1870) 回复(0)

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...

by cvamy11 - Python - 2010-06-09 23:49:02 阅读(3921) 回复(10)

如何在扩展中返回字典?

by ipy - Python - 2007-10-09 16:10:18 阅读(2178) 回复(0)

我要用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 请大家看看,我这个程序该怎么写...

by among29 - Python - 2012-11-03 11:39:01 阅读(20156) 回复(10)

麻烦各位大侠帮看看这个程序的返回值为啥不是零???谢谢! #! /usr/bin/python import re import os import sys import gzip def rmN(Args): if not Args: print 'Usage: rmN ' print 'Max_N_ratio [float] , e.g. 0.05' sys.exit(0) if re.search('gz$|gzip$', Args[0]): infile = gzip.open(Args[0], 'rb') else: infile = open(Args[0], 'r') maxN = float(Args[1]) outfile...

by ganhy - Python - 2013-11-04 14:06:31 阅读(4069) 回复(6)

请教各位大牛一个问题: python的os模块,在调用os.system()命令后,看python文档知道,返回的参数应该是该shell命令的返回值,正确为0,错误为非0 但是我发现如果该shell脚本的运行时间很长(脚本是正确的),调用os.system命令会直接返回一个非0参数,而我想用这个返回值做下一步的操作就执行不了了。 想请教各位大牛这种情况要如何解决啊,谢谢!

by 又小又白 - Shell - 2013-01-18 18:27:35 阅读(1551) 回复(0)

if( sign_weights.find("1110:") )!=-1:我想查找有这个字符串 但是这个有缺陷,如果有子串是111110:的这样也会匹配到。 有没有办法搜索以1110:开头的, 我试了前面加个^,但是好像不行

by liumilan2009 - Python - 2014-01-16 21:24:36 阅读(5220) 回复(4)

小弟是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...

by shichunda - Python - 2012-06-26 15:54:44 阅读(1104) 回复(6)

[qq]564332055[/qq] 请问一下这图片里面的小程序是不是还缺少一部分,我照这个样子写总是报错,望大虾们给我指点指点。也可以加我QQ,希望能请教各位

by python初学者 - Linux新手园地 - 2011-04-09 13:32:31 阅读(2773) 回复(3)

python初学,下面的异常题请教是什么情况? >>> def con(x,y): result=x+y return result con(1,2) SyntaxError: invalid syntax >>> con Traceback (most recent call last): File "", line 1, in con NameError: name 'con' is not defined >>> def con(x,y): result=x+y return result a=con(1,2) SyntaxError: invalid syntax >>> a=1 >>> a=con(1,2) Traceback (most recent call last): ...

by 白痴小新 - Python - 2010-12-27 21:35:12 阅读(2748) 回复(6)