我有一些输入数据,输入文件中的时间戳是从文件名中指定的日期时间开始的小时数.
这有点无用,所以我需要将它转换为python datetime.datetime对象,然后将它放在一个numpy数组中.我可以写一个for循环,但我想做的事情如下:
numpy.arange(datetime.datetime(2000, 1,1), datetime.datetime(2000, 1,2), datetime.timedelta(hours=1))
Run Code Online (Sandbox Code Playgroud)
这会引发TypeError.
可以这样做吗?我坚持使用python 2.6和numpy 1.6.1.
我正在使用一个streamwriter与后台工作者一起进行日志记录.
就这样,我有
System::Void
MyUI::execBWorker_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
String^ outputPath = _clr::Settings::ApplicationLogPath("_log.txt", true, false);
logfile_ = gcnew StreamWriter(outputPath,true);
DoStuff();
logfile_->Close();
}
Run Code Online (Sandbox Code Playgroud)
DoStuff()方法中的内容引发了Progress事件.
System::Void
MyUI::execBWorker_ProgressChanged(System::Object^ sender, System::ComponentModel::ProgressChangedEventArgs^ e) {
logfile_->WriteLine("something");
}
Run Code Online (Sandbox Code Playgroud)
我觉得这真的很有气味.我怎样才能让它变得更好,或者至少如何检查日志文件是否尚未关闭?有很多消息,所以我担心连续打开和关闭日志文件.
我有一个postgresql数据库,其中包含drupal制作的一些表格,以及我自己制作的其他表格.然后我有一个使用pyodbc的python api来查询数据库.
只有一个表,我无法通过pyodbc选择.如果我打印查询并将其粘贴到pgadminIII中,那么它会给出预期的结果,如果我在python代码中更改了表,它会给出正确的结果.
查询是
select id from a_company where name = 'somename'
Run Code Online (Sandbox Code Playgroud)
结果
7
8
9
Run Code Online (Sandbox Code Playgroud)
等(50行int id)
我的python代码是
sql = """select id from a_company where name = 'somename'"""
curs = self._connection.cursor()
sql = self._ConvertToPostGres(sql) #drops [] etc, as the initial code was for MSSQL
curs.execute(sql)
f = curs.fetchall()
Run Code Online (Sandbox Code Playgroud)
通过pyodbc的调用返回
None
Run Code Online (Sandbox Code Playgroud)
(我可以使用相同的连接从其他表中进行选择,因此连接字符串无关紧要?)
我最好的猜测是这是一个权限问题,而且我已经用这个特定的表做了一些蠢事.
任何人都可以建议如何调试这个?
通过pgadmin创建表:
-- Table: a_company
-- DROP TABLE a_company;
CREATE TABLE a_company
(
id integer NOT NULL DEFAULT nextval('a_company_id_seq'::regclass),
name character varying,
abn character varying,
url character …
Run Code Online (Sandbox Code Playgroud) 我正在使用sql server 2008 R2,我有两个表,区域和设施.两者都有一个包含地理元素的列.
我想在地理元素的交集处计算联合,如下所示:
SELECT * from Regions join Facilities on [Regions].[geography].STIntersects([Facilities].[geography])
Run Code Online (Sandbox Code Playgroud)
这当然不起作用.区域是大多边形,设施是每个点仅包含在一个多边形中的点.
我可以写一些(伪代码)
for each r in Regions:
for each f in Facilities:
if f.[geography].STIntersects(r.[geography]):
print r, f
Run Code Online (Sandbox Code Playgroud)
但是使用数据库的全部意义在于操作集合而不是元素,当然?
那么,有更好的方法吗?
谢谢梅兰妮
我有一个
List<string> myList = new List<string>();
Run Code Online (Sandbox Code Playgroud)
告诉我在一些输入数据中应该找到的所有内容.我想把它变成一个
Dictionary<string, bool> myDict = Dictionary<string, bool>();
Run Code Online (Sandbox Code Playgroud)
字典键与列表条目相同,所有值均为false.然后,我将遍历数据,并在找到元素时更新字典值.
这似乎很简单,但是
Dictionary<string, bool> myDict = myList.ToDictionary<string, bool>(x => false);
Run Code Online (Sandbox Code Playgroud)
由于错误而无效:
无法隐式转换
Dictionary<bool, string>
为Dictionary<string, bool>
我试图找出VisualHint.SmartPropertyGrid.PropertyGrid是否满足我设置属性的需要,我的一些属性是布尔值.
其中一个参数是
// container:
// The instance of an object containing the C# property displayed in this new
// property.
Run Code Online (Sandbox Code Playgroud)
所以一般来说,我可以把它交给一个合适的对象 - 但是,布尔值是值类型,而不是对象.
在C#中,正确的语法是输入容器typeof(bool)
.有没有明智的方法在C++中做到这一点,还是我必须制作自己的bool对象?
.net ×2
c# ×2
c++-cli ×2
python ×2
clr ×1
datetime ×1
dictionary ×1
linq ×1
list ×1
numpy ×1
postgresql ×1
pyodbc ×1
sql ×1
sqlgeography ×1
streamwriter ×1
t-sql ×1
timedelta ×1
types ×1