Оформлението на входа на python

Примерен код

1
0

оформлението на входа на python

from io import StringIO

def enter_name():
	name = input('Please enter name: ')
    return 'Hello ' + name

# Suppose we want to mock John as an input for a test
# All inputs end with a newline character
mock_input = StringIO('John\n')

# monkeypatch is the parameter passed in test to mock certain values
def test_enter_name(monkeypatch):
    # Here 'sys.stdin' is used to specifically mock the standard input
    # The mock has to be set before the function being tested is run
  	monkeypatch.setattr('sys.stdin', mock_input)
    assert enter_name() == 'Hello John'

Подобни страници

Подобни страници с примери

На други езици

Тази страница на други езици

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Íslensk
..................................................................................................................