pythonⅠ中的条件跳过

2024-10-02 22:30:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试这样的东西

def scanthefile():
    x = 11
    if x > 5
        """ i want to come out of if and go to end of scanfile """
        print x

     return info

更新:

如果必须检查文件的内容大小。如果内容大小大于一个值,比如500,那么我应该转到扫描文件的末尾


Tags: and文件oftogo内容ifdef
3条回答

如果我理解你的问题,但我真的不确定,你可以取消缩进:

x = 11
if x > 5:
    pass # Your code goes here.
print x

好吧,回答你的更新:

import os

fn = 'somefile.txt'
thefile = open(fn, 'r')

# The next line check the size of the file. Replace "stat(fn).st_size" with your own code if you want.
if stat(fn).st_size > 500:
    thefile.seek(0, os.SEEK_END)
# you are now at the end of the file if the size is > 500

你所说的“到文件末尾”是指“查找文件末尾”吗?然后:

import os

   ...

if x > 5:
  thefile.seek(0, os.SEEK_END)

如果你的意思完全不同,你最好澄清一下!在

相关问题 更多 >