V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
xudongsong
V2EX  ›  Python

想问下正文中的 Ruby 代码如果用 Python 该怎么实现

  •  
  •   xudongsong · 2015-04-01 17:19:19 +08:00 · 1702 次点击
    这是一个创建于 3350 天前的主题,其中的信息可能已经有所发展或是发生改变。

    def run(desc, &block)
    puts "\n#{desc} start @ #{Time.now}"
    block.call
    if !$?.nil?
    warn "#{desc} fail" unless $?.success?
    puts "#{desc} #{$?.success? ? 'success' : 'fail'} @ #{Time.now}"
    exit $?.exitstatus unless $?.success?
    end
    end

    run "cd" do
    system 'mkdir test' unless File.exist?('test')
    system "cd test"
    end

    run "ls" do
    system "ls"
    end

    其实主要是不知道block该怎么改写

    1 条回复    2015-04-07 00:19:26 +08:00
    ming2281
        1
    ming2281  
       2015-04-07 00:19:26 +08:00
    没有缩进,没有"食欲"啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5239 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 448ms · UTC 01:30 · PVG 09:30 · LAX 18:30 · JFK 21:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.