我正在创建一个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的答案.但是,我得到一个 ImportError有win32console,这可能是因为提到的问题不是Python3.4,但我是.另外,我想知道这是否可以使用标准库,而不是外部库.
假设我创建了这个类:
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?
我上课了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)
和两个类Champion和Spell:
public class Spell extends GameObject{
//Some methods …Run Code Online (Sandbox Code Playgroud)