我在python中遇到一个奇怪的错误.当我尝试使用zip模块提取受密码保护的文件时,在尝试将"oy"设置为密码时出现异常.其他一切似乎都有效.ZipFile模块中的错误?
import zipfile
zip = zipfile.ZipFile("file.zip", "r")
zip.setpassword("oy".encode('utf-8'))
zip.extractall() #Above password "oy" generates the error here
zip.close()
Run Code Online (Sandbox Code Playgroud)
这是我得到的例外:
Traceback (most recent call last):
File "unzip.py", line 4, in <module>
zip.extractall()
File "C:\Program Files\Python32\lib\zipfile.py", line 1002, in extrac
l
self.extract(zipinfo, path, pwd)
File "C:\Program Files\Python32\lib\zipfile.py", line 990, in extract
return self._extract_member(member, path, pwd)
File "C:\Program Files\Python32\lib\zipfile.py", line 1035, in _extra
member
shutil.copyfileobj(source, target)
File "C:\Program Files\Python32\lib\shutil.py", line 65, in copyfileo
buf = fsrc.read(length)
File "C:\Program Files\Python32\lib\zipfile.py", line 581, in read
data …Run Code Online (Sandbox Code Playgroud) 我将一些Individual对象存储在切片中。在将其附加到切片之前,我先打印Individual对象的名称。
将其存储在切片中之后,我将其检索为指针,并希望将名称更改为"Peter",但是更改仍然有效,因为它仍然可以打印"Steve"。为什么?
type Individual interface {
GetName() *string
SetName(name string)
}
type Person struct {
name string
}
// Implement functions of the Individual interface
func (p Person) GetName() *string {
return &p.name
}
func (p Person) SetName(newName string) {
name := p.GetName();
*name = newName
}
var individuals []Individual
func main() {
person := Person{name: "Steve"}
fmt.Println(person)
individuals = append(individuals, person) // append Person to slice
p1 := individuals[0] // Retrieve …Run Code Online (Sandbox Code Playgroud) 我想改变ExtJS文本字段的颜色,但我没有成功.标签是获取颜色的组件:
var textfield= Ext.create('Ext.form.Text',
{
id: 'textfield',
name: 'name',
fieldLabel: 'Name',
style: 'background-color: #ddd;',
allowBlank: false,
});
Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [textfield]
});
Run Code Online (Sandbox Code Playgroud)
示例:http: //jsfiddle.net/3ZZcZ/
如何更改颜色?
我有一个Person带有一些元素的xsd文件.一些元素具有属性minOccurs和maxOccurs集合.xsd文件中的两行可能如下所示.
<xsd:element name="NameOfElement" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="NameOfAnotherElement" minOccurs="0">
Run Code Online (Sandbox Code Playgroud)
在NetBeans中,我想使用JAXB生成此xsd文件的Java类.只有minOccurs属性的所有元素都在生成的Personjava文件中获取set和get方法,但在xsd文件中设置了两个minOccurs和maxOccurs属性的元素将成为List.所以上面的xsd行在生成之后就变成了这个:
@XmlElement(name = NameOfElement)
protected List<Person.NameOfElement> nameOfElement;
@XmlElement(name = NameOfAnotherElement)
protected Person.NameOfAnotherElement nameOfAnotherElement;
Run Code Online (Sandbox Code Playgroud)
奇怪的是,变量nameOfAnotherElement在Personjava类中同时nameOfElement获取set和get方法,并且只获取get方法.
为什么List<>在Java代码中成为元素的元素不会获得set方法(那些具有属性minOccurs并maxOccurs在xsd中设置的元素)?
所以我的问题是我不能将NameOfElement设置为Person对象,因为它错过了set方法,但它包含一个get方法!为什么会这样?
我已经用JBoss 7.1.1建立了一个maven项目,我想使用JavaEE库.在我设置的root pom.xml中:
<repositories>
<repository>
<id>jboss</id>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
Run Code Online (Sandbox Code Playgroud)
我在根pom.xml和ejb maven模块的pom.xml中有这个:
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.2.Final</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我这样做时,maven clean install我收到此错误:
Failed to execute goal on project myproject-ejb: Could not resolve dependencies for project myproject:myproject-ejb:ejb:1.0-SNAPSHOT: Failure to find org.jboss.spec:jboss-javaee-6.0:jar:3.0.2.Final in https://repository.jboss.org/nexus/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of jboss has elapsed or updates are forced -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
我的配置怎么了?
编辑1
如果我从根pom.xml中删除jboss存储库,我收到此错误:
[ERROR] Failed to execute goal on project myproject-ejb: …Run Code Online (Sandbox Code Playgroud) 我知道有一些C++的线程库,比如Pthread,Boost等,但它们是如何工作的?必须在某处实现逻辑.
假设我想在C++中编写自己的线程机制,而不是使用任何库,我该如何开始?写这篇文章时我应该记住什么?
我想知道如何将onClick()方法添加到Ext.form.Text组件.
如果组件是一个按钮,那么我所要做的就是添加这一行:
handler: function() {alert("Hello!");}
Run Code Online (Sandbox Code Playgroud)
但是,如果组件是文本字段,则该行不起作用.看下面的例子:
Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
id: 'myButton',
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
style: 'background-color: #ddd;',
allowBlank: false,
handler: function() {Ext.getCmp('myButton').setValue("TEXT")} // Does not work!
}, {
xtype: 'button',
name: 'email',
fieldLabel: 'Email Address',
style: 'background-color: green',
textfieldStyle: 'background-color: green',
handler: function() {Ext.getCmp('myButton').setValue("TEXT")} // Works!
}]
});
Run Code Online (Sandbox Code Playgroud) 我希望我的jtextfield只接受介于0和MAX下面的代码示例中指定的值之间的数值.
假设MAX变量设置为8,如下所示.然后我只想让它可以输入0到8之间的数值.在我下面的代码示例中,您可以键入88,77,66等,这是不可能的.我不知道如何才能做到这一点所以它只接受0到0之间的值MAX.
import javax.swing.*;
import javax.swing.text.*;
public class DocumentDemo extends JFrame {
public static void main(String[] args) {
new DocumentDemo();
}
final int MAX = 8;
public DocumentDemo() {
this.setVisible(true);
JTextField textField = new JTextField();
((AbstractDocument)textField.getDocument()).setDocumentFilter(
new DocumentFilter() {
@Override
public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
int len = text.length();
boolean isValidValue = true;
for(int i = 0; i < len; i++) {
if(!Character.isDigit(text.charAt(i))){
isValidValue …Run Code Online (Sandbox Code Playgroud) 如果所有都具有默认值,是否可以在Python中设置函数调用中的几个参数?
示例:在ftplib.FTP模块中定义:
ftplib.FTP([host[, user[, passwd[, acct[, timeout]]]]])
Run Code Online (Sandbox Code Playgroud)
所有这些参数都有一个默认值,因此您不需要全部设置它们,例如,您可以调用ftp = ftplib.FTP()以获取FTP对象.但是,如果我只想设置timeout参数怎么办?我怎么做到这一点?
我想在过去的7天内获取最高值(来自名为value的列).我试过这个sql:
SELECT MAX(value) as value_of_week
FROM events
WHERE event_date > UNIX_TIMESTAMP() -(7 * 86400);
Run Code Online (Sandbox Code Playgroud)
但是它给了我86.1,比今天的7天还要早.鉴于下面的行,我应该得到55.2与日期2014-05-16 07:07:00.
id value event_date
1 28. 2014-04-18 08:23:00
2 23.6 2014-04-22 06:43:00
3 86.1 2014-04-29 05:32:00
4 43.3 2014-05-03 08:12:00
5 55.2 2014-05-16 07:07:00
6 25.6 2014-05-19 06:11:00
Run Code Online (Sandbox Code Playgroud)