与Genie/vala中的原始输入()等价?

2024-06-01 15:53:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Genie创建一个简单的helloworld程序,但是我希望能够在终端上输入一些输入。我的目标是在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)

我做错什么了?你知道吗

谢谢。你知道吗


Tags: namehelloyouris错误errorprogramam
2条回答

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中的原始输入()一样。很高兴知道,而且我不知道如何找到有关特定函数的信息以及如何导入它们。我来自R,在那里我可以用吗?function(),这会给我一些关于它的说明。精灵和瓦拉有什么相似的地方吗?你知道吗

如果愿意,可以编写自己的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 + "!"

相关问题 更多 >