Найти - Пользователи
Полная версия: Вложенные функции
Начало » Центр помощи » Вложенные функции
1 2 3
Tenebras
Пытаюсь осилить вложенные функции.
Работа скрипта останавливается после “port_type = int(raw_input('Enter the port type (/dev/ttyUSB - ”1“ | /dev?ttyACM - ”2“ ): '))”

Где я таки весь не прав???

Код:

 import serial
def port():
	port_type = int(raw_input('Enter the port type (/dev/ttyUSB - "1" |  /dev?ttyACM - "2" ): '))
	return port_type
	def port_t(port_type):
		if port_type == int(1):
			num = int(raw_input('Enter the port number (/dev/ttyUSBx): '))
			adress_a = str('/dev/ttyUSB')
		elif port_type == int(2):
			num = int(raw_input('Enter the port number (/dev/ttyACMx): '))
			adress_a = str('/dev/ttyACM')
		else:
			print 'Invalid Input!'
		return num, adress_a
		def number(num):
			port_number = str(num)
			adress = str(adress_a + port_number)
			return adress
port()
print adress


FishHook
У вас возврат из функции после port_type = int…., чего вы от нее хотите?
Tenebras
Можно пояснить?
FishHook
 def port():
	port_type = int(raw_input('Enter the port type (/dev/ttyUSB - "1" |  /dev?ttyACM - "2" ): '))
	return port_type

Что по-вашему делает return? Это немедленный выход из функции, почему вы ждете, что функция продолжит свое выполнение после того, как произошел return?
Tenebras
Убрал - эффекта нет, тот же результат
FishHook
Tenebras
Убрал - эффекта нет, тот же результат
И какой же именно результат?
Что по-вашему делает функция raw_input('Enter the port type (/dev/ttyUSB - “1” | /dev?ttyACM - “2” ): ')?
Tenebras
Просит ввести 1 или 2, а потом присваивает результат переменной port_type

FishHook
И что происходит после того, как вы вводите?
И что по-вашему должно происходить?
Tenebras
 tenebras@meteolab:~/PyProg/Arduino$ python ttyUSBx.py
Enter the port type (/dev/ttyUSB - "1" |  /dev?ttyACM - "2" ): 1

Больше ни чего не происходит
Tenebras
ТО есть скрипт завешается
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB