等价于 Genie/vala 中的 raw_input()?
The equivalent of raw_input() in Genie/vala?
我正在尝试使用 Genie 创建一个简单的 Hello World 程序,但我希望能够在终端上输入一些内容。我的 objective 是在 Genie 中重复以下 python 代码:
#!/usr/bin/env python
print 'Hello. I am a python program.'
name = raw_input("What is your name? ")
print "Hello there, " + name + "!"
到目前为止我所做的是;
[indent=4]
uses System
init
print "Hello. I am a python program."
var name = Console.ReadLine("What is your name? ")
print "Hello there, " + name + "!"
但是我得到了一些错误,可能是因为我对语言一无所知,这是错误:
hw.gs:4.5-4.10: error: The namespace name `System' could not be found
System
^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
hw.gs:3.6-3.11: error: The namespace name `System' could not be found
uses System
^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
我做错了什么?
谢谢。
BigOldTree 帮我提了一个建议,这个建议确实奏效了。以下是 Geanie 中的代码:
[indent=4]
init
print "Hello. I am a python program."
print "What's your name?"
var name = stdin.read_line()
print "Hello there, " + name + "!"
我不知道是否可以像 python 中的 raw_input() 那样向 stdin.read_line() 发送参数。很高兴知道这一点,我也不知道如何找到有关特定功能的信息以及如何导入它们。我来自 R,在那里我可以使用 ?function(),这会给我一些关于它的说明。 Genie/Vala 上有类似的东西吗?
如果愿意,您可以编写自己的 raw_input
函数:
[indent=4]
def raw_input (query : string? = null) : string?
if (query != null)
stdout.printf ("%s\n", query)
return stdin.read_line ()
init
print "Hello. I am a python program."
var name = raw_input ("What's your name?")
print "Hello there, " + name + "!"
我正在尝试使用 Genie 创建一个简单的 Hello World 程序,但我希望能够在终端上输入一些内容。我的 objective 是在 Genie 中重复以下 python 代码:
#!/usr/bin/env python
print 'Hello. I am a python program.'
name = raw_input("What is your name? ")
print "Hello there, " + name + "!"
到目前为止我所做的是;
[indent=4]
uses System
init
print "Hello. I am a python program."
var name = Console.ReadLine("What is your name? ")
print "Hello there, " + name + "!"
但是我得到了一些错误,可能是因为我对语言一无所知,这是错误:
hw.gs:4.5-4.10: error: The namespace name `System' could not be found
System
^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
hw.gs:3.6-3.11: error: The namespace name `System' could not be found
uses System
^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
我做错了什么?
谢谢。
BigOldTree 帮我提了一个建议,这个建议确实奏效了。以下是 Geanie 中的代码:
[indent=4]
init
print "Hello. I am a python program."
print "What's your name?"
var name = stdin.read_line()
print "Hello there, " + name + "!"
我不知道是否可以像 python 中的 raw_input() 那样向 stdin.read_line() 发送参数。很高兴知道这一点,我也不知道如何找到有关特定功能的信息以及如何导入它们。我来自 R,在那里我可以使用 ?function(),这会给我一些关于它的说明。 Genie/Vala 上有类似的东西吗?
如果愿意,您可以编写自己的 raw_input
函数:
[indent=4]
def raw_input (query : string? = null) : string?
if (query != null)
stdout.printf ("%s\n", query)
return stdin.read_line ()
init
print "Hello. I am a python program."
var name = raw_input ("What's your name?")
print "Hello there, " + name + "!"