我目前面临将tinyDB python包导入python的问题。
这些是我用raspbian安装tinyDB的步骤。 1.运行命令:sudo pip3 install tinydb
输出说: 要求已经满足(使用--upgrade升级):/usr/local/lib/python3.4/dist-packages中的tinydb
这意味着已成功安装tinydb软件包并安装了setup.py。
这是我在python中导入tinydb的代码。
代码:
Traceback (most recent call last):
File "/home/pi/mp/mp.py", line 4, in <module>
db = TinyDB('/home/pi/Desktop/csv/book.json')
File "/usr/local/lib/python3.4/dist-packages/tinydb/database.py", line 93, in __init__
self._table = self.table(table)
File "/usr/local/lib/python3.4/dist-packages/tinydb/database.py", line 110, in table
table = self.table_class(StorageProxy(self._storage, name), **options)
File "/usr/local/lib/python3.4/dist-packages/tinydb/database.py", line 202, in __init__
data = self._read()
File "/usr/local/lib/python3.4/dist-packages/tinydb/database.py", line 277, in _read
return self._storage.read()
File "/usr/local/lib/python3.4/dist-packages/tinydb/database.py", line 31, in read
raw_data = (self._storage.read() or {})[self._table_name]
File "/usr/local/lib/python3.4/dist-packages/tinydb/storages.py", line 105, in read
return json.load(self._handle)
File "/usr/lib/python3.4/json/__init__.py", line 268, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.4/json/decoder.py", line 346, in decode
raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 7 column 1 - line 73 column 1 (char 212 - 2423)
但是,将tinydb导入python时会出现此错误: ImportError:无法导入名称&#39; TinyDB&#39;
更新
修复了模块未找到错误,但现在又出现了其他错误。 错误:
<script>
// Assign attribute specific "data-scroll-speed" to elements upon loading, resizing and scrolling of the webpage page. "if/else" is depending on if #image-ul is fully above the bottom edge of the browser window.
$(document).ready(function() {
$(window).on('load resize scroll', function() {
var WindowScrollTop = $(this).scrollTop(),
Div_one_top = $('#image-ul').offset().top,
Div_one_height = $('#image-ul').outerHeight(true),
Window_height = $(this).outerHeight(true);
if (WindowScrollTop + Window_height >= (Div_one_top + Div_one_height)) {
$('#sloganenglish').attr('data-scroll-speed', '2');
$('.slow-scroll-slider').attr('data-scroll-speed', '5');
$('.slogan-a-line').css('color', 'green');
} else {
$('#sloganenglish').attr('data-scroll-speed', '1');
$('.slow-scroll-slider').attr('data-scroll-speed', '1');
$('.slogan-a-line').css('color', 'red');
}
}).scroll();
});
// data-scroll-speed script
$.fn.moveIt = function() {
var $window = $(window);
var instances = [];
$(this).each(function() {
instances.push(new moveItItem($(this)));
});
window.onscroll = function() {
var scrollTop = $window.scrollTop();
instances.forEach(function(inst) {
inst.update(scrollTop);
});
}
}
var moveItItem = function(el) {
this.el = $(el);
this.speed = parseInt(this.el.attr('data-scroll-speed'));
};
moveItItem.prototype.update = function(scrollTop) {
var pos = scrollTop / this.speed;
this.el.css('transform', 'translateY(' + -pos + 'px)');
};
// Initialization
$(function() {
$('[data-scroll-speed]').moveIt();
});
</script>