问题列表 - 第46182页

使用imp动态导入模块

我试图动态地从不同的目录导入模块.我正在回答这个问题的答案.我在名为foo的目录中有一个名为bar的模块.主脚本将在父目录中运行到foo.

这是我到目前为止在我的测试脚本中的代码(它在父目录中运行到foo)

#test.py
import imp

mod = imp.load_source("bar","./foo")
Run Code Online (Sandbox Code Playgroud)

和bar.py的代码

#bar.py
class bar:

    def __init__(self):
          print "HELLO WORLD"
Run Code Online (Sandbox Code Playgroud)

但是,当我运行test.py时,我收到此错误:

Traceback (most recent call last):
  File "C:\Documents and Settings\user\Desktop\RBR\test.py", line 3, in <module>
    mod = imp.load_source("bar","./foo")
IOError: [Errno 13] Permission denied
Run Code Online (Sandbox Code Playgroud)

python import dynamic

18
推荐指数
1
解决办法
3万
查看次数

为什么tableVieW:viewForHeaderInSection忽略我的UILabel的frame属性?

基本上我想改变我的节头的字体和颜色,所以我实现tableVieW:viewForHeaderInSection.首先我尝试了这段代码:

-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UILabel* headerLabel = [[[UILabel alloc] init] autorelease];
    headerLabel.frame = CGRectMake(10, 0, 300, 40);
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.textColor = [UIColor blackColor];
    headerLabel.font = [UIFont boldSystemFontOfSize:18];
    headerLabel.text = @"My section header";

    return headerLabel;
}
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,框架属性被忽略(我在谈论左边的10px插图).现在我使用以下内容:

-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView* headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)] autorelease];

    UILabel* headerLabel = [[UILabel alloc] init];
    headerLabel.frame = CGRectMake(10, 0, 300, 40);
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.textColor = [UIColor blackColor];
    headerLabel.font …
Run Code Online (Sandbox Code Playgroud)

iphone frame uitableview

16
推荐指数
1
解决办法
1万
查看次数

用于查询亚马逊产品的优秀PHP库?

哪个是查询亚马逊书籍(CD和其他产品)的最佳PHP库?我看着zend,看起来不错.亚马逊有官方图书馆吗?我找不到一个产品,但他们似乎有其他产品的综合库,如简单的数据库,弹性云等.

php amazon amazon-web-services

5
推荐指数
1
解决办法
9951
查看次数

如何获得由FactoryBean spring创建的bean?

FactoryBean的可用于以编程方式创建,这可能需要复杂的实例化逻辑的对象.

但是,似乎由它创建的bean FactoryBean不会成为弹簧管理.这种解释是否正确?如果是这样,有什么好的解决方法吗?包含一个简短的代码示例来说明我的问题.

ApplicationContext的:

<bean id="searcher" class="some.package.SearcherFactory" /> 
<bean id="service" class="some.package.Service" /> 
Run Code Online (Sandbox Code Playgroud)

工厂实施:

public class SearcherFactory implements FactoryBean<Searcher> {

    @Override
    public Searcher getObject() throws Exception {
        return new Searcher(); // not so complex after all ;)
    }

    @Override
    public Class<Searcher> getObjectType() {
        return Searcher.class;
    }
    .... 
}
Run Code Online (Sandbox Code Playgroud)

工厂创建的类:

public class Searcher() {
      private Service service;

      @Autowired
      public void setService(Service service) {
           // never invoked
           this.service=service;
      } 
}
Run Code Online (Sandbox Code Playgroud)

java spring autowired

33
推荐指数
3
解决办法
7万
查看次数

13
推荐指数
2
解决办法
1万
查看次数

我该如何修剪一个单词?

例如,我想要修剪一半的字

Washington
Run Code Online (Sandbox Code Playgroud)

修剪之后应该是 washi

Chicago
Run Code Online (Sandbox Code Playgroud)

修剪之后应该是 chic

Tokyo
Run Code Online (Sandbox Code Playgroud)

修剪之后应该是 tok

php string

-2
推荐指数
1
解决办法
522
查看次数

如何从main方法自动启动程序

这是我的代码

def main():
    # This code reads in data.txt and loads it into an array
    # Array will be used to add friends, remove and list
    # when we quit, we'll overwrite original friends.txt with
    # contents 

    print"Welcome to the program"

    print "Enter the correct number"
    print "Hockey fan 1, basketball fan 2, cricket fan 3"
    choice = input("Select an option")

    while choice!=3:
        if choice==1:
            addString = raw_input("Who is your favorite player??")
            print "I love Kessel"
        elif choice==2:
            remInt = …
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
1万
查看次数

使用python 3和unicode写入文件

这是我的代码:

import codecs
filename = "worst.txt"
file = open(filename, "r",encoding='utf-8')
lines = file.readlines()
texte = ""
for line in lines:
    print(line)
    texte += line
file.close()
print(texte)
texte = texte.split(";")
print(texte)
filename = "oudean.html"



file = open(filename, "w",encoding='utf-8')



file.write("<html><body>\r\n")
for t in texte :
        print(t)
        file.write("""<img src="ouedan.jpg"><br>\r\n""")
        file.write("""Une déclaration à faire ?<br>Besoin d'encouragements?<br>Notre brigade d'élite beat agent est là pour vous aider.<br>Faites appel à nous en appelant le  06 et nous accourrons vous encourager dans l'instant.<br>N hésitez pas.<br>Et pour vous aider …
Run Code Online (Sandbox Code Playgroud)

unicode encode file python-3.x

6
推荐指数
1
解决办法
2万
查看次数

使用没有attatched委托方法在C#中触发事件?

我刚刚在程序中遇到一个错误,我正在编写一个异常被抛出的状态,说明"对象引用必须设置为对象的实例".经过调查,我发现在尝试触发事件时抛出了此异常,但事件没有添加任何委托方法.

我想检查一下我的理解是否正确,作为开发人员,如果没有先检查事件是否等于null,就不应该触发事件?例如:

if (this.MyEventThatIWantToFire != null)
{
    this.MyEventThatIWantToFire();
}
Run Code Online (Sandbox Code Playgroud)

提前感谢您的建议/想法.

c# null events delegates nullreferenceexception

5
推荐指数
1
解决办法
2794
查看次数

与其他语言相比,在Java中开发服务器端应用程序有哪些优势?

我们公司正在开始开发客户端 - 服务器应用程序,并正在讨论应该使用哪些技术.对于客户端(GUI),我们倾向于QT和C++.对于服务器端,我们建议使用Java,实际上它看起来是最常用于服务器开发的语言之一.任何人都可以详细说明Java为服务器端开发提供的优势,以及为什么采用它应该使我们的开发人员更容易和/或让我们达到比我们使用的更好的结果,假设.NET,甚至C++?提前致谢.

java

3
推荐指数
1
解决办法
3833
查看次数