V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Apr 1, 2015 · 2103 views
    This topic created in 4053 days ago, the information mentioned may be changed or developed.

    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 replies    2015-04-07 00:19:26 +08:00
    ming2281
        1
    ming2281  
       Apr 7, 2015
    没有缩进,没有"食欲"啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6316 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 02:39 · PVG 10:39 · LAX 19:39 · JFK 22:39
    ♥ Do have faith in what you're doing.