我正在尝试从阳光基础打开此API的URL,并从json中的页面返回数据.这是我生成的代码,减去myapikey周围的括号.
import urllib.request.urlopen
import json
urllib.request.urlopen("https://sunlightlabs.github.io/congress/legislators?api_key='(myapikey)")
Run Code Online (Sandbox Code Playgroud)
我得到这个错误
Traceback (most recent call last):
File "<input>", line 1, in <module>
ImportError: No module named request.urlopen
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?香港专业教育学院研究了https://docs.python.org/3/library/urllib.request.html仍然没有进展
我有一个rtf文件,其中有一些带有项目符号的文本,如下面的屏幕截图所示
我想提取数据和子弹,但是当我在控制台中打印时,我得到了垃圾值.如何从控制台打印完全相同的内容.我尝试的方式如下
public static void main(String[] args) throws IOException, BadLocationException {
RTFEditorKit rtf = new RTFEditorKit();
Document doc = rtf.createDefaultDocument();
FileInputStream fis = new FileInputStream("C:\\Users\\Guest\\Desktop\\abc.rtf");
InputStreamReader i =new InputStreamReader(fis,"UTF-8");
rtf.read(i,doc,0);
System.out.println(doc.getText(0,doc.getLength()));
}
Run Code Online (Sandbox Code Playgroud)
控制台输出:
我认为垃圾值是由于控制台不支持chareset所以我试图生成一个pdf文件,但在pdf中我也得到相同的垃圾值.这是pdf代码
Paragraph de=new Paragraph();
Phrase pde=new Phrase();
pde.add(new Chunk(getText("C:\\Users\\Guest\\Desktop\\abc.rtf"),smallNormal_11));
de.add(pde);
de.getFont().setStyle(BaseFont.IDENTITY_H);
document.add(de);
public static String getText() throws IOException, BadLocationException {
RTFEditorKit rtf = new RTFEditorKit();
Document doc = rtf.createDefaultDocument();
FileInputStream fis = new FileInputStream("C:\\Users\\Guest\\Desktop\\abc.rtf");
InputStreamReader i =new InputStreamReader(fis,"UTF-8");
rtf.read(i,doc,0);
String output=doc.getText(0,doc.getLength());
return output;
}
Run Code Online (Sandbox Code Playgroud) 尝试实现 apriori 算法并使其达到可以提取所有事务中一起出现的子集的程度。
这就是我所拥有的:
subsets = [set(['Breakfast & Brunch', 'Restaurants']), set(['American (Traditional)', 'Breakfast & Brunch']), set(['American (Traditional)', 'Restaurants']), set(['American (Traditional)', 'Breakfast & Brunch']), set(['Breakfast & Brunch', 'Restaurants']), set(['American (Traditional)', 'Restaurants'])]
Run Code Online (Sandbox Code Playgroud)
例如set(['Breakfast & Brunch', 'Restaurants'])出现两次,我需要跟踪出现的次数以及相应的模式。
我尝试使用:
from collections import Counter
support_set = Counter()
# some code that generated the list above
support_set.update(subsets)
Run Code Online (Sandbox Code Playgroud)
但它会产生这个错误:
supported = itemsets_support(transactions, candidates)
File "apriori.py", line 77, in itemsets_support
support_set.update(subsets)
File"/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/collections.py", line 567, in update
self[elem] = self_get(elem, 0) + 1
TypeError: unhashable type: 'set' …Run Code Online (Sandbox Code Playgroud) 我的日期时间选择器适用于第一次单击,但如果我再次在输入字段中单击,它会显示带有日期字段的选择器。我怎样才能做到这一点?任何帮助将不胜感激。
这是第一次点击时的图像(预期行为)
这是第二次点击的图像(预期行为与第一次相似)
我的代码在下面
<div class='input-group' id='dpRM'>
<input type='text' class="form-control form-control-1 form-input input-sm fromq" placeholder="Enter Month and year" />
<span class="input-group-addon">
<span class="fa fa-calendar"></span>
</span>
</div>
Run Code Online (Sandbox Code Playgroud)
<script type="text/javascript">
$(function() {
$('#dpRM').datetimepicker({
format: "MMMM YYYY",
viewMode: "years",
//minViewMode: 0,
toolbarPlacement: "top",
allowInputToggle: true,
icons: {
time: 'fa fa-time',
date: 'fa fa-calendar',
up: 'fa fa-chevron-up',
down: 'fa fa-chevron-down',
previous: 'fa fa-chevron-left',
next: 'fa fa-chevron-right',
today: 'fa fa-screenshot',
clear: 'fa fa-trash',
close: 'fa fa-remove'
}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
提前致谢
twitter-bootstrap bootstrap-datetimepicker eonasdan-datetimepicker
我有这个Angular2组件,我尝试使用PersonServie发出两个HTTP并行请求(工作正常).但该Observable.forkJoin方法抛出此错误:EXCEPTION: TypeError: this._subscribe is not a function in [null]
评估getIdentificationTypes()和getPerson()功能,每个返回一个Observable对象.
我错过了什么?
import { Component, OnInit } from 'angular2/core';
import { Router, RouteParams } from 'angular2/router';
import {ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from 'angular2/router';
import { Observable } from 'rxjs/Rx';
import 'rxjs/Rx';
// more imports for models and other components//
@Component({
selector: 'my-coponent',
templateUrl: 'template',
directives: [ROUTER_DIRECTIVES]
})
export class MyComponent implements OnInit {
public identificationTypes: IdentificationType[];
public person : Person;
// some public and …Run Code Online (Sandbox Code Playgroud) 我对 Python 非常陌生,正在尝试创建和打印 Excel 电子表格。郑重声明一下,我在 C 和 C++ 编程方面拥有多年的经验。我在 Windows 7 上使用 Python 3.5.1 和 OpenPyxl 并使用 xlsx 文件。下面复制了我用来重复前 2 行作为重复页眉的代码片段:
import openpyxl
from openpyxl.workbook import Workbook
from openpyxl.worksheet.properties import WorksheetProperties
...
sheet.print_options.gridLines = True
sheet.print_title_rows = '1:2' #**problem code not working as intended**
sheet.page_setup.orientation = sheet.ORIENTATION_LANDSCAPE
...
Run Code Online (Sandbox Code Playgroud)
除活动工作表中 print_title_rows 的赋值语句外,上述所有其他设置均按预期工作。如果论坛上的专家们能够为我指明正确的方向,我将非常感激。珍惜您的时间。
list_example = "['0101612-0', '0101611-2', '0101610-4', '0101608-8', '0101607-0', '0101606-2', '0100786-3', '0100784-8', '0100783-0', '0100782-2', '0100781-4', '0100780-6', '0100779-8', '0100778-0', '0100777-2']"
Run Code Online (Sandbox Code Playgroud)
我想将上面转换成这样:
list_example = ['0101612-0', '0101611-2', '0101610-4', '0101608-8', '0101607-0', '0101606-2', '0100786-3', '0100784-8', '0100783-0', '0100782-2', '0100781-4', '0100780-6', '0100779-8', '0100778-0', '0100777-2']
Run Code Online (Sandbox Code Playgroud)
我尝试了以下:list_example = list_example.split(',')结果是:
["['0101612-0'",
" '0101611-2'",
" '0101610-4'",
" '0101608-8'",
" '0101607-0'",
" '0101606-2'",
" '0100786-3'",
" '0100784-8'",
" '0100783-0'",
" '0100782-2'",
" '0100781-4'",
" '0100780-6'",
" '0100779-8'",
" '0100778-0'",
" '0100777-2']"]
Run Code Online (Sandbox Code Playgroud)
从中提取值很混乱。
python ×4
angular ×1
data-mining ×1
java ×1
observable ×1
openpyxl ×1
python-3.x ×1
rtf ×1
url ×1
urllib ×1