小编Mri*_*lla的帖子

使用cx_freeze时如何捆绑其他文件?

我在Windows系统上使用Python 2.6和cx_Freeze 4.1.2.我已经创建了setup.py来构建我的可执行文件,一切正常.

当cx_Freeze运行时,它会将所有内容移动到build目录中.我有一些其他文件,我想包含在我的build目录中.我怎样才能做到这一点?这是我的结构:

src\
    setup.py
    janitor.py
    README.txt
    CHNAGELOG.txt
    helpers\
        uncompress\
            unRAR.exe
            unzip.exe
Run Code Online (Sandbox Code Playgroud)

这是我的片段:

建立

( name='Janitor',
  version='1.0',
  description='Janitor',
  author='John Doe',
  author_email='john.doe@gmail.com',
  url='http://www.this-page-intentionally-left-blank.org/',
  data_files = 
      [ ('helpers\uncompress', ['helpers\uncompress\unzip.exe']),
        ('helpers\uncompress', ['helpers\uncompress\unRAR.exe']),
        ('', ['README.txt'])
      ],
  executables =
      [
      Executable\
          (
          'janitor.py', #initScript
          )
      ]
)
Run Code Online (Sandbox Code Playgroud)

我似乎无法让这个工作.我需要一个MANIFEST.in文件吗?

python distutils cx-freeze

54
推荐指数
2
解决办法
4万
查看次数

如何实现Iterable接口?

给定以下代码,如何迭代ProfileCollection类型的对象?

public class ProfileCollection implements Iterable {    
    private ArrayList<Profile> m_Profiles;

    public Iterator<Profile> iterator() {        
        Iterator<Profile> iprof = m_Profiles.iterator();
        return iprof; 
    }

    ...

    public Profile GetActiveProfile() {
        return (Profile)m_Profiles.get(m_ActiveProfile);
    }
}

public static void main(String[] args) {
     m_PC = new ProfileCollection("profiles.xml");

     // properly outputs a profile:
     System.out.println(m_PC.GetActiveProfile()); 

     // not actually outputting any profiles:
     for(Iterator i = m_PC.iterator();i.hasNext();) {
        System.out.println(i.next());
     }

     // how I actually want this to work, but won't even compile:
     for(Profile prof: m_PC) {
        System.out.println(prof);
     }
}
Run Code Online (Sandbox Code Playgroud)

java iterator

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

使用反射获取带注释的字段列表

我创建了我的注释

public @interface MyAnnotation {
}
Run Code Online (Sandbox Code Playgroud)

我把它放在测试对象的字段中

public class TestObject {

    @MyAnnotation 
    final private Outlook outlook;
    @MyAnnotation 
    final private Temperature temperature;
     ...
}
Run Code Online (Sandbox Code Playgroud)

现在我想得到所有字段的列表MyAnnotation.

for(Field field  : TestObject.class.getDeclaredFields())
{
    if (field.isAnnotationPresent(MyAnnotation.class))
        {
              //do action
        }
}
Run Code Online (Sandbox Code Playgroud)

但似乎我的块执行操作永远不会执行,并且字段没有注释,因为以下代码返回0.

TestObject.class.getDeclaredField("outlook").getAnnotations().length;
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我并告诉我我做错了什么吗?

java reflection annotations

51
推荐指数
2
解决办法
5万
查看次数

如何将查询参数附加到现有URL?

我想将键值对作为查询参数附加到现有URL.虽然我可以通过检查URL是否有查询部分或片段部分来执行此操作,并通过跳过一堆if子句来执行追加,但我想知道如果通过Apache执行此操作是否有干净的方法Commons库或类似的东西.

http://example.com 将会 http://example.com?name=John

http://example.com#fragment 将会 http://example.com?name=John#fragment

http://example.com?email=john.doe@email.com 将会 http://example.com?email=john.doe@email.com&name=John

http://example.com?email=john.doe@email.com#fragment 将会 http://example.com?email=john.doe@email.com&name=John#fragment

我之前已多次运行此场景,并且我希望在不破坏URL的情况下执行此操作.

java url

50
推荐指数
5
解决办法
8万
查看次数

为什么我的Gradle会因退出代码137而死亡?

我一直在尝试编译和测试一个大项目来使用Gradle.测试运行正常,直到他们意外死亡.我挖了一下,资源说这是由于内存问题.如果我减少套件中的测试数量,它运行正常.

我将内存增加了4倍,增加了调试级别,但我仍然没有遵循导致这种情况的原因.这是一个非常神秘的堆栈跟踪.最后一行(向右滚动)显示我定义的内存设置.

...
...
...

1125 tests completed, 30 failed, 9 skipped
:test FAILED
:test (Thread[Daemon worker,5,main]) completed. Took 8 mins 39.684 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> Process 'Gradle Test Executor 1' finished with non-zero exit value 137

* Try:
Run with --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':test'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) …
Run Code Online (Sandbox Code Playgroud)

java junit gradle gradlew build.gradle

50
推荐指数
5
解决办法
2万
查看次数

如何在Python中比较日期和日期时间?

这是我正在尝试执行的一小段代码:

>>> from datetime import *
>>> item_date = datetime.strptime('7/16/10', "%m/%d/%y")
>>> from_date = date.today()-timedelta(days=3)
>>> print type(item_date)
<type 'datetime.datetime'>
>>> print type(from_date)
<type 'datetime.date'>
>>> if item_date > from_date:
...     print 'item is newer'
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't compare datetime.datetime to datetime.date
Run Code Online (Sandbox Code Playgroud)

我似乎无法比较日期和日期时间值.比较这些最好的方法是什么?我应该将日期时间转换为日期,反之亦然?我如何在他们之间进行转换.

(一个小问题,但似乎有点令人困惑.)

python

47
推荐指数
3
解决办法
10万
查看次数

JSDoc在文档中添加实际代码

你知道<code />JSDoc中是否有某种标签吗?我需要在我的文档中添加代码片段,如下所示:

/**
 * This function does something see example below:
 *
 * var x = foo("test"); //it will show "test" message
 *
 * @param {string} str: string argument that will be shown in message
 */
function foo(str)
{
   alert(str);
}
Run Code Online (Sandbox Code Playgroud)

我需要将注释中的代码作为代码显示在JSDoc中(如果没有突出显示语法,至少像预先格式化或具有灰色背景的东西).

javascript documentation jsdoc

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

有什么方法可以在用户关闭设备时收到通知吗?

我需要知道用户何时关闭他/她的手机.是否有任何广播(或类似)在用户手机关机时通知?

android broadcastreceiver

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

MinGW的简单解释

我是一个狂热的Python用户,似乎我需要在我的Windows机器上安装MinGW来编译一些库.我对MinGW和GCC有点困惑.这是我的问题(从真实的虚拟观点来看):

所以Python是解释和编译的语言.有Linux的Linux和Windows实现,只需安装并使用二进制文件来执行他的代码.它们捆绑了一堆你可以使用的内置库.我读过的内容与Ruby相同.

现在,我已经完成了C的一小部分,我知道有人可以编译它.它有自己的内置库,可以使用它们称为头文件.现在,回到学校的那天,C,正在一个名为Turbo-C的vi类IDE中编写代码,然后按F9编译它.这几乎是我的C教育结束的地方.

什么是MinGW,什么是GCC?我一直主要研究Windows系统,甚至最近开始使用Cygwin.他们不一样吗?

对这些区域进行简单解释会有所帮助.

(如果这篇文章听起来很愚蠢/愚蠢,我很抱歉.我以为我会问这里.忽略这些核心位从来没有让任何人成为更好的程序员.)

感谢大家.

c windows gcc cygwin mingw

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

如何在MacOSX中为JRE 7安装无限强度的JCE?

我为MacOSX安装了Oracle JRE 7(不是JDK),但我无法找到放置JCE管辖区文件的位置.

我需要用无限强度版本替换它们.

java macos jce

39
推荐指数
3
解决办法
4万
查看次数