问题:为什么我不能打开数据库?
信息:我正在开发一个目的不重要但使用sqlite3数据库的项目.我制作了一个测试程序,它运行并传递给它创建数据库的位置:
sqlite3
单元测试程序可以使db没问题.然后,我实际上使用该程序,将相同的位置传递给它,它说
OperationalError:无法打开数据库文件
我尝试过使用空数据库.与数据库单元测试留下,没有数据库.在所有三种情况下,我都会收到此错误.最令人沮丧的部分必须是单元测试可以做得很好,但实际的程序不能.
关于到底发生了什么的任何线索?
...现在我知道这个问题已被多次询问了,我已经看过这些其他主题了.到目前为止,没有任何工作,从使用sys.path.append('.')到导入foo
我有一个python文件,希望导入一个文件(在其父目录中).你能帮我弄清楚我的子文件如何成功导入其父目录中的文件.我正在使用python 2.7
结构是这样的(每个目录中都有__ init __ .py文件):
StockTracker/
__ Comp /
____ a.py
____ SubComp /
__ _ __ _b.py
在b.py里面,我想导入a.py:所以我尝试了下面的每一个但是我仍然在b.py里面写了一个错误,说"没有这样的模块"
import a
import .a
import Comp.a
import StockTracker.Comp.a
import os
import sys
sys.path.append('.')
import a
sys.path.remove('.')
Run Code Online (Sandbox Code Playgroud) 我一直在使用这个简单的脚本从文本生成图像:
<?php
header('Content-type: image/png');
$color = RgbfromHex($_GET['color']);
$text = urldecode($_GET['text']);
$font = 'arial.ttf';
$im = imagecreatetruecolor(400, 30);
$bg_color = imagecolorallocate($im, 255, 255, 255);
$font_color = imagecolorallocate($im, $color[0], $color[1], $color[2]);
imagefilledrectangle($im, 0, 0, 399, 29, $bg_color);
imagettftext($im, 20, 0, 10, 20, $font_color, $font, $text);
imagepng($im);
imagedestroy($im);
function RgbfromHex($hexValue) {
if(strlen(trim($hexValue))==6) {
return array(
hexdec(substr($hexValue,0,2)), // R
hexdec(substr($hexValue,2,2)), // G
hexdec(substr($hexValue,4,2)) // B
);
}
else return array(0, 0, 0);
}
?>
Run Code Online (Sandbox Code Playgroud)
我用file.php调用脚本?text = testing script&color = 000000
现在我想知道如何在同一图像中混合使用普通和粗体字体生成文本,例如 file.php?text=testing <b>script</b>&color=000000
感谢dqhendricks帮助我解决这个问题. …
我正在尝试使用AJAX根据框中选择的内容动态生成JquerUI手风琴.目前我有
<div style="display:none" id="testselect">
</div>
Run Code Online (Sandbox Code Playgroud)
用JS
$("#courseselect").change(function () {
$("#testselect").html(""); // Empty any previous data
$("#testselect").css("display", "block"); // Display it if it was hidden
$.getJSON('json.php?show=tests&courseid=' + $(this).val(), function(data) {
for(x in data)
{
$("#testselect").append("<h3 value=\"" + data[x].uno + "\"><a href=\"#\">" + data[x].name + "</a></h3>");
$("#testselect").append("<div>Foo</div>");
}
$("#testselect").accordion({ change:function(event, ui) { courseid = ui.newHeader.attr("value");
} });
});
});
Run Code Online (Sandbox Code Playgroud)
现在,这是我第一次更改选择时的工作,但之后它将恢复为普通的未格式化的HTML.好像从未完成对.accordion()的调用.我猜这与JQuery有关,不希望我格式化两次,但我真的不知道.
我的桌子:
create table MyTable (
Id int identity(1,1) not null,
MyStatus char(2) not null
)
insert into MyTable(MyStatus) select 'A'
Run Code Online (Sandbox Code Playgroud)
类和枚举:
public class MyTable
{
public virtual int Id { get; set; }
public virtual MyTableStatus MyStatus { get; set; }
}
public enum MyTableStatus
{
A,
B
}
Run Code Online (Sandbox Code Playgroud)
制图:
public MyTableMap()
{
Id(x => x.Id);
Map(x => x.MyStatus);
}
Run Code Online (Sandbox Code Playgroud)
当我执行以下测试时,我得到System.FormatException:输入字符串的格式不正确...
[Test]
public void Blah()
{
MyTable myTable = Session.Get<MyTable>(1);
Assert.That(myTable.MyStatus, Is.EqualTo(MyTableStatus.A));
}
Run Code Online (Sandbox Code Playgroud)
将枚举映射到数据库中的字符串表示形式的正确方法是什么?
编辑 - 我在现有数据库上编写应用程序,我无法轻易修改,因为它也被其他应用程序使用.所以数据库中的一些字段(我想在我的应用程序中表示为枚举)是int类型和一些char(2)类型.
我想获取应用程序的包标识符,给出它的路径.
例如:
NSString* vlcFilePath = @"/Applications/VLC.app"
Run Code Online (Sandbox Code Playgroud)
NSWorkspace如果它是活动应用程序,我知道如何使用bundle标识符,但在这种情况下,它不一定是活动应用程序.
我的网站有PHP命令:
mysql_query("SELECT * FROM users WHERE id=" . $_GET["id"]) or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)
当我输入URL
http://example.com/index.php?id=1;%20UPDATE%20users%20SET%20password=123%20WHERE%20id=1
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE users SET password=abc WHERE id=1' at line 1
但在phpmyamin查询执行成功.这有什么不对?为什么它不在浏览器中执行?
我正在与Sinatra和Redis 在Facebook上重建恋人,我想要:
每个用户都有两个Redis有序集(reqSent&reqRecv),用于存储uid.在SCORE我们为了通过请求是time(UNIX时间戳)提出请求.我使用有序集而不是列表,因为用户可能只将请求类型(rid)编码为数字并添加到uid之前.(rid | uid)例如,对于uid = 100的用户,我们可能会:
100:reqSent => ["1|123", "2|123", "2|134"] # format: ["rid|tid"]
100:reqRecv => ["3|343", "5|142", "4|2224"] # format: ["rid|uid"]
Run Code Online (Sandbox Code Playgroud)
MongoDB原生支持地理空间索引,所以我想改用它.
否则,我应该如何使用Redis实现地理空间索引?我应该用太阳黑子(localsolr)吗?显然,你可以使用Redis的太阳黑子.
我有以下目录布局:
runner.py
lib/
tests/
testsuite1/
testsuite1.py
testsuite2/
testsuite2.py
testsuite3/
testsuite3.py
testsuite4/
testsuite4.py
Run Code Online (Sandbox Code Playgroud)
testsuite*.py模块的格式如下:
import pytest
class testsomething:
def setup_class(self):
''' do some setup '''
# Do some setup stuff here
def teardown_class(self):
'''' do some teardown'''
# Do some teardown stuff here
def test1(self):
# Do some test1 related stuff
def test2(self):
# Do some test2 related stuff
....
....
....
def test40(self):
# Do some test40 related stuff
if __name__=='__main()__'
pytest.main(args=[os.path.abspath(__file__)])
我遇到的问题是我想并行执行'testsuites',即我希望testsuite1,testsuite2,testsuite3和testsuite4并行开始执行,但是测试套件中的单个测试需要连续执行.
当我使用py.test中的'xdist'插件并使用'py.test -n 4'启动测试时,py.test正在收集所有测试并随机地在4个工作者之间平衡测试.这导致在'testsuitex.py'模块中每次测试时都会执行'setup_class'方法(这违背了我的目的.我希望每个类只执行一次setup_class,然后在那里连续执行测试).
基本上我想要的执行看起来像是:
worker1: executes all …
python ×3
php ×2
bundle ×1
enums ×1
gd ×1
geolocation ×1
geospatial ×1
identifier ×1
image ×1
imagettftext ×1
indexing ×1
javascript ×1
jquery ×1
jquery-ui ×1
mysql ×1
netbeans ×1
nhibernate ×1
objective-c ×1
pytest ×1
redis ×1
sqlite ×1
string ×1
sunspot ×1
xdist ×1