shares_1 = [50, 100, 75, 200]
shares_2 = [100, 100, 300, 500]
shares_1.extend(shares_2)
print shares_1
Run Code Online (Sandbox Code Playgroud)
输出[50,100,75,200,100,100,300,500]
我想要的是将一个变量分配给合并列表并对列表进行排序.看到我的错误尝试下面的任何建议?
shares_3.sort() = shares_1.extend(shares_2)
Run Code Online (Sandbox Code Playgroud)
谢谢!
我有一个类似下面的文本文件:
this000is00a00test001251!!
this000is00a00test001251!!
this000is00a00test001251!!
this000is00a00test001251!!
Run Code Online (Sandbox Code Playgroud)
我有以下代码来解析它:
def file_open():
my_file = open(r'C:\Users\test\Desktop\parse_me.txt','r', encoding='cp1252')
return my_file
def parse(current_line):
seq_1 = (current_line[0:4])
seq_2 = (current_line[7:9])
seq_3 = (current_line[11:12])
seq_4 = (current_line[14:18])
seq_5 = (current_line[20:24])
return(seq_1, seq_2, seq_3, seq_4, seq_5)
def export_file(current_file):
for line in current_file:
x = parse(line)
print (x)
export_file(file_open())
Run Code Online (Sandbox Code Playgroud)
这是我在解释器中得到的输出:
('this', 'is', 'a', 'test', '1251')
('this', 'is', 'a', 'test', '1251')
('this', 'is', 'a', 'test', '1251')
('this', 'is', 'a', 'test', '1251')
Run Code Online (Sandbox Code Playgroud)
我想看到的是这样格式的文本:
this is a test 1251
Run Code Online (Sandbox Code Playgroud)
要么
this,is,a,test,1251
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?或者你有什么好的链接解释3.0中的文本格式?
谢谢!
当我将返回值设置为a时List,我有一个LINQ查询,但是我只想返回一个IQueryable<Post>.我该怎么办?
public List<Post> GetPostByID(int id)
{
var thePost = (from p in _context.Posts
where p.Id == id
select p).ToList();
return thePost;
}
Run Code Online (Sandbox Code Playgroud) 我的烧瓶应用程序的目录结构如下所示.我有一个主应用程序文件夹,下面有两个单独的文件夹.一个用于某些db作业,我将安排另一个用于烧瓶应用程序.关于我需要做什么才能从每个应用程序文件夹访问数据库的任何想法?
--MainApp
----__init__.py
----database.db
------FlaskWebApp
--------__init__.py
--------runserver.py
------DBJobs
--------__init__.py
--------dbJobsMain.py
Run Code Online (Sandbox Code Playgroud)
我想要做的是从runserver.py或dbJobsMain.py访问database.db文件.关于我为实现这一目标必须做些什么的任何想法?或者有更好的方法来构建这个应用程序?
谢谢!
我正在研究linq方法,似乎无法获得与方法签名匹配的返回类型.任何指导都将非常感谢.
谢谢!
private static IEnumerable<KeyValuePair<string, string>> RunQuery(XDocument doc)
{
var data = from b in doc.Descendants("Company")
where b.Attribute("name").Value == "CompanyA"
from y in b.Descendants("Shirt")
from z in y.Descendants("Size")
select new
{
color = y.Attribute("id").Value,
price = z.Value
};
return data;
}
Run Code Online (Sandbox Code Playgroud) 我似乎无法在我的标记中的输入元素中插入JSON值.任何想法?我确实验证了.ajax调用返回了正确的JSON.它可能很简单,但我似乎无法让它工作.谢谢!
HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/jquery-2.0.3.min.js"></script>
</head>
<body>
<div>
<form>
<fieldset>
<legend>The Person</legend>
<label>Name: </label>
<input id="Name"/>
<label>Age: </label>
<input id="Age" />
</fieldset>
</form>
</div>
<script type="text/javascript" src="~/Scripts/Custom.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JavaScript的
$(document).ready(function () {
$.ajax({
url: '/Home/GetPerson',
type: 'GET',
success: function (result) {
alert(JSON.stringify(result));
$('#Name').val(result[0].FirstName);
}
});
});
Run Code Online (Sandbox Code Playgroud)
JSON.stringify返回
{"FirstName": "Steve", "LastName": "Smith"}
Run Code Online (Sandbox Code Playgroud)