小编ikh*_*unt的帖子

如何在输入行中输入文本:如何在命令行上询问用户输入,同时提供用户可以编辑或删除的"默认"答案?

我正在创建一个Python脚本,要求从命令行输入.用户可以编辑文件的一部分.我可以要求提供新信息并在文件中覆盖它,没问题.但我宁愿将文件的编辑部分放在命令行中,因此不必完全输入.这可能吗?

文件:

1|This file
2|is not empty
Run Code Online (Sandbox Code Playgroud)

例:

>>>edit line 2
Fetching line 2
Edit the line then hit enter
>>>is not empty                  #This is written here by the script, not by the user
Run Code Online (Sandbox Code Playgroud)

然后可以改为

>>>is not full either
Edited file
Run Code Online (Sandbox Code Playgroud)

该文件已更改为:

1|This file
2|is not full either
Run Code Online (Sandbox Code Playgroud)

我希望我很清楚我想要完成什么.

据说这个问题在一定程度上回答了我的问题.当我运行Linux时,它会这样做readline.但是,我不是.我正在使用Windows而我没有使用readline.我想只使用标准库.
该问题还提供了Windows的答案.但是,我得到一个 ImportErrorwin32console,这可能是因为提到的问题不是Python3.4,但我是.另外,我想知道这是否可以使用标准库,而不是外部库.

python python-3.x

16
推荐指数
2
解决办法
1736
查看次数

是否有必要始终在构造函数中调用它?

假设我创建了这个类:

public class Panel extends JPanel{
    private JTextBox textBox;
    public Panel(){
        this.textBox = new JTextBox(10);
        add(this.textBox);
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的主要:

public class Main{
    public static void main(String[] args){
        Panel panel1 = new Panel();
        Panel panel2 = new Panel();
    }
}
Run Code Online (Sandbox Code Playgroud)

在课堂上Panel,是否有必要this在每一行打电话,还是可以把它丢弃?或者它会弄乱Panels?

java this

0
推荐指数
1
解决办法
70
查看次数

对象互相覆盖

我上课了GameObject:

public class GameObject{

    private Coordinate coordinates;

    public GameObject(){
        coordinates = new Coordinate();
    }

    public void setCoordinates(int x, int y){
        coordinates.x = x;
        coordinates.y = y;
    }

    //More methods here   
}

public class Coordinate{

    public int x, y;

    public Coordinate(){

    }

    public Coordinate(int x, int y){
        this.x = x;
        this.y = y;
    }

    public void setCoordinate(int x, int y){
        this.x = x;
        this.y = y;
    }
Run Code Online (Sandbox Code Playgroud)

和两个类ChampionSpell:

public class Spell extends GameObject{
    //Some methods …
Run Code Online (Sandbox Code Playgroud)

java extends object

0
推荐指数
1
解决办法
109
查看次数

标签 统计

java ×2

extends ×1

object ×1

python ×1

python-3.x ×1

this ×1