2006年11月22日 星期三 20:29
pythoners, 是不是我眼花了,下面的代码有编译错误,5555555 ................................................. outfilew = None try: outfilew = open(outfile,'a',1024) outfilew.write('Find %s lines in file: %s' % ( len(outLines), filename)) outfilew.writelines(outLines) except IOError: print 'Find %s lines in file: %s' % ( len(outLines), filename) print '\n'.join(outLines) finally : if outfilew:outfilew.close() ................................................. > D:\software\Python24\pythonw.exe -u "D:\_tmp_\listjava.py" File "D:\_tmp_\listjava.py", line 47 finally : ^ SyntaxError: invalid syntax 这是什么错误??? -- _ >` ) - msn: trydofor在hotmail.com ( ( \ - url: www.trydofor.com ---``|\ ---------------------------------------- ___|___ __|___|__ |____ | | | __|___|__ / / |___|___| | | _/ / __/ ---|--- /\ /\ /|\ / \ __/ \____ __/ | \__ ___/ \_
2006年11月22日 星期三 20:34
On 11/22/06, shirj <shirj在livedoor.cn> wrote: > pythoners, > > 是不是我眼花了,下面的代码有编译错误,5555555 > try_stmt ::= try_exc_stmt | try_fin_stmt try_exc_stmt ::= "try" ":" suite ("except" [expression ["," target]] ":" suite)+ ["else" ":" suite] try_fin_stmt ::= "try" ":" suite "finally" ":" suite Try 的语法是 except 和 不能混合使用! try: ... try: ... except: .... finally: .... 这样才可以混合的, > ................................................. > outfilew = None > try: > outfilew = open(outfile,'a',1024) > outfilew.write('Find %s lines in file: %s' % ( > len(outLines), filename)) > outfilew.writelines(outLines) > except IOError: > print 'Find %s lines in file: %s' % ( len(outLines), filename) > print '\n'.join(outLines) > finally : > if outfilew:outfilew.close() > > ................................................. > > > D:\software\Python24\pythonw.exe -u "D:\_tmp_\listjava.py" > File "D:\_tmp_\listjava.py", line 47 > finally : > ^ > SyntaxError: invalid syntax > > 这是什么错误??? > > -- > _ > >` ) - msn: trydofor在hotmail.com > ( ( \ - url: www.trydofor.com > ---``|\ ---------------------------------------- > ___|___ __|___|__ |____ > | | | __|___|__ / / > |___|___| | | _/ / > __/ ---|--- /\ > /\ /|\ / \ > __/ \____ __/ | \__ ___/ \_ > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -- """Time is unimportant, only life important! blog@ http://blog.zoomquiet.org/pyblosxom/ wiki@ http://wiki.woodpecker.org.cn/moin/ZoomQuiet douban@ http://www.douban.com/people/zoomq/ ____________________________________ Please use OpenOffice.org to stand for M$ office. Please use 7-zip to stand for WinRAR. You can get realy freedom from software. """
2006年11月22日 星期三 20:43
thanks, 是这样啊:) 我看到http://www.python.org/dev/peps/pep-0341/ try:except Exception: finally: 是不是能在新版中支持,期望中.... Zoom.Quiet wrote: > On 11/22/06, shirj <shirj在livedoor.cn> wrote: >> pythoners, >> >> 是不是我眼花了,下面的代码有编译错误,5555555 >> > try_stmt ::= try_exc_stmt | try_fin_stmt > try_exc_stmt ::= "try" ":" suite > ("except" [expression ["," target]] ":" suite)+ > ["else" ":" suite] > try_fin_stmt ::= "try" ":" suite "finally" ":" suite > > Try 的语法是 except 和 不能混合使用! > > try: > ... > try: > ... > except: > .... > finally: > .... > > 这样才可以混合的, >> ................................................. >> outfilew = None >> try: >> outfilew = open(outfile,'a',1024) >> outfilew.write('Find %s lines in file: %s' % ( >> len(outLines), filename)) >> outfilew.writelines(outLines) >> except IOError: >> print 'Find %s lines in file: %s' % ( len(outLines), filename) >> print '\n'.join(outLines) >> finally : >> if outfilew:outfilew.close() >> >> ................................................. >> >>> D:\software\Python24\pythonw.exe -u "D:\_tmp_\listjava.py" >> File "D:\_tmp_\listjava.py", line 47 >> finally : >> ^ >> SyntaxError: invalid syntax >> >> 这是什么错误??? >> >> -- >> _ >> >` ) - msn: trydofor在hotmail.com >> ( ( \ - url: www.trydofor.com >> ---``|\ ---------------------------------------- >> ___|___ __|___|__ |____ >> | | | __|___|__ / / >> |___|___| | | _/ / >> __/ ---|--- /\ >> /\ /|\ / \ >> __/ \____ __/ | \__ ___/ \_ >> >> _______________________________________________ >> python-chinese >> Post: send python-chinese在lists.python.cn >> Subscribe: send subscribe to python-chinese-request在lists.python.cn >> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn >> Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -- _ >` ) - msn: trydofor在hotmail.com ( ( \ - url: www.trydofor.com ---``|\ ---------------------------------------- ___|___ __|___|__ |____ | | | __|___|__ / / |___|___| | | _/ / __/ ---|--- /\ /\ /|\ / \ __/ \____ __/ | \__ ___/ \_
2006年11月22日 星期三 20:46
> > 是这样啊:) > > 我看到http://www.python.org/dev/peps/pep-0341/ > try: >> except Exception: > > finally: > > > 是不是能在新版中支持,期望中.... python2.5 里 except else finally 可以同时用。 -- http://codeplayer.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20061122/6033f5f9/attachment.html
2006年11月22日 星期三 21:13
2.5中可以使用try-except-finally On 11/22/06, shirj <shirj at livedoor.cn> wrote: > thanks, > > 是这样啊:) > > 我看到http://www.python.org/dev/peps/pep-0341/ > try: >> except Exception: > > finally: > > > 是不是能在新版中支持,期望中.... > > Zoom.Quiet wrote: > > On 11/22/06, shirj <shirj at livedoor.cn> wrote: > >> pythoners, > >> > >> 是不是我眼花了,下面的代码有编译错误,5555555 > >> > > try_stmt ::= try_exc_stmt | try_fin_stmt > > try_exc_stmt ::= "try" ":" suite > > ("except" [expression ["," target]] ":" suite)+ > > ["else" ":" suite] > > try_fin_stmt ::= "try" ":" suite "finally" ":" suite > > > > Try 的语法是 except 和 不能混合使用! > > > > try: > > ... > > try: > > ... > > except: > > .... > > finally: > > .... > > > > 这样才可以混合的, > >> ................................................. > >> outfilew = None > >> try: > >> outfilew = open(outfile,'a',1024) > >> outfilew.write('Find %s lines in file: %s' % ( > >> len(outLines), filename)) > >> outfilew.writelines(outLines) > >> except IOError: > >> print 'Find %s lines in file: %s' % ( len(outLines), filename) > >> print '\n'.join(outLines) > >> finally : > >> if outfilew:outfilew.close() > >> > >> ................................................. > >> > >>> D:\software\Python24\pythonw.exe -u "D:\_tmp_\listjava.py" > >> File "D:\_tmp_\listjava.py", line 47 > >> finally : > >> ^ > >> SyntaxError: invalid syntax > >> > >> 这是什么错误??? > >> > >> -- > >> _ > >> >` ) - msn: trydofor at hotmail.com > >> ( ( \ - url: www.trydofor.com > >> ---``|\ ---------------------------------------- > >> ___|___ __|___|__ |____ > >> | | | __|___|__ / / > >> |___|___| | | _/ / > >> __/ ---|--- /\ > >> /\ /|\ / \ > >> __/ \____ __/ | \__ ___/ \_ > >> > >> _______________________________________________ > >> python-chinese > >> Post: send python-chinese at lists.python.cn > >> Subscribe: send subscribe to python-chinese-request at lists.python.cn > >> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > >> Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > > -- > _ > >` ) - msn: trydofor at hotmail.com > ( ( \ - url: www.trydofor.com > ---``|\ ---------------------------------------- > ___|___ __|___|__ |____ > | | | __|___|__ / / > |___|___| | | _/ / > __/ ---|--- /\ > /\ /|\ / \ > __/ \____ __/ | \__ ___/ \_ > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -- GoogleTalk: qcxhome at gmail.com MSN: qcxhome at hotmail.com My Space: tkdchen.spaces.live.com BOINC: boinc.berkeley.edu 中国分布式计算总站: www.equn.com
Zeuux © 2025
京ICP备05028076号