我正在寻找类似于Bash'!!
的功能。
在Bash中,如果键入!!
,它会将其替换为您键入的最后一个命令。例如,如果您键入which deactivate
,然后键入cat $(!!)
,则第二个命令将重新格式化为cat $(which deactivate)
。
在IPython中输入!!
会给你留下一个空列表,我怀疑它是在试图从两个空字符串shell命令中传递一个输出列表。
是否有类似的方法将最后一个命令格式化为IPython中新键入的命令?
答案 0 :(得分:3)
您可以通过引用输入数字来获取IPython中的任何先前输入:
<head>
<title>TODO list</title>
<link rel="stylesheet" type="text/css" href="assests/css/todos.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
<script type="text/javascript" src="assests/js/lib/jquery-3.2.1.min.js"></script>
</head>
<body>
<div id="container">
<h1>TO-DO List<i class="fa fa-plus"></i></h1>
<input type="text" placeholder="Add New Todo">
<ul>
<li><span><i class="fa fa-trash"></i></span> Go To Potions Class</li>
<li><span><i class="fa fa-trash"></i></span> Buy New Robes</li>
<li><span><i class="fa fa-trash"></i></span> Visit Hogrid</li>
</ul>
</div>
<script type="text/javascript" src="assests/js/todos.js"></script>
</body>
如果您想获取当前行的上一个输入,可以使用h1{
background: #2980b9;
color: white;
margin: 0;
padding: 10px 20px;
text-transform: uppercase;
font-size: 24px;
font-weight: normal;
}
ul{
list-style: none;
margin: 0;
padding: 0;
}
#container{
box-shadow: 0 0 3px rgba(0,0,0, 0.1);
width: 360px;
margin: 100px auto;
background: #f7f7f7;
}
.completed{
color: gray;
text-decoration: line-through;
}
body{
font-family: 'Roboto', sans-serif;
background: #2BC0E4; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #EAECC6, #2BC0E4); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #EAECC6, #2BC0E4); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
li{
background: white;
height: 40px;
line-height: 40px;
color: #666;
}
li:nth-child(2n){
background: #f7f7f7;
}
input{
font-size: 18px;
background:#f7f7f7;
width: 100%;
padding: 13px 13px 20px 20px;
box-sizing:border-box;
color: #2980b9;
border:3px solid rgba(0,0,0,0);
}
input:focus{
background:white;
border: 3px solid #2980b9;
outline: none;
}
.fa-plus{
float: right;
}
span{
background-color: #e74c3c;
height:40px;
margin-right: 20px;
text-align: center;
color: white;
width:0px;
display:inline-block;
transition: 0.2s linear;
opacity:0;
}
li:hover span{
width:40px;
opacity:1.0;
}
或$("ul").on("click","li",function(){
$(this).toggleClass("completed");
});
//click on X to delete TODO
$("ul").on("click","span",function(event){
//to remove parent lis
$(this).parent().fadeOut(500,function(){
$(this).remove();
});
event.stopPropagation();
});
//adding new TODO
$("input[type='text'").keypress(function(event){
if(event.which===13){
//grabbing new TODO text from input
var todoText= $(this).val();
$(this).val("");
//create a new li and add to ul
$("ul").append("<li><span><i class='fa fa-trash'><span> " + todoText +"</li>")
}
});
(In [4]: 'hello'
Out[4]: 'hello'
In [5]: In[4]
Out[5]: "'hello'"
引用当前输入):
_i