小编CDs*_*ace的帖子

列出对象的属性

有没有办法获取类实例上存在的属性列表?

class new_class():
    def __init__(self, number):
        self.multi = int(number) * 2
        self.str = str(number)

a = new_class(2)
print(', '.join(a.SOMETHING))
Run Code Online (Sandbox Code Playgroud)

期望的结果是将输出"multi,str".我希望这能看到脚本各个部分的当前属性.

python class python-3.x

256
推荐指数
12
解决办法
51万
查看次数

将过滤器设置为OpenFileDialog以允许典型的图像格式?

我有这个代码,我怎么能让它接受所有典型的图像格式?PNG,JPEG,JPG,GIF?

这是我到目前为止所拥有的:

public void EncryptFile()
{            
    OpenFileDialog dialog = new OpenFileDialog();
    dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
    dialog.InitialDirectory = @"C:\";
    dialog.Title = "Please select an image file to encrypt.";

    if (dialog.ShowDialog() == DialogResult.OK)
    {
        //Encrypt the selected file. I'll do this later. :)
    }             
}
Run Code Online (Sandbox Code Playgroud)

请注意,过滤器设置为.txt文件.我可以改为PNG,但其他类型呢?

c# openfiledialog winforms

217
推荐指数
9
解决办法
37万
查看次数

用于终止与数据库的所有连接的脚本(超过RESTRICTED_USER ROLLBACK)

我有一个开发数据库,​​经常从Visual Studio数据库项目(通过TFS自动构建)重新部署.

有时当我运行我的构建时,我收到此错误:

ALTER DATABASE failed because a lock could not be placed on database 'MyDB'. Try again later.  
ALTER DATABASE statement failed.  
Cannot drop database "MyDB" because it is currently in use.  
Run Code Online (Sandbox Code Playgroud)

我试过这个:

ALTER DATABASE MyDB SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE
Run Code Online (Sandbox Code Playgroud)

但我仍然无法删除数据库.(我的猜测是大多数开发人员都dbo可以访问.)

我可以手动运行SP_WHO并开始查杀连接,但我需要一种自动方式在自动构建中执行此操作.(虽然这次我的连接是我试图丢弃的数据库中唯一的连接.)

是否有一个脚本可以删除我的数据库,无论谁连接?

sql t-sql sql-server sql-server-2008 sql-server-2008-r2

214
推荐指数
4
解决办法
48万
查看次数

为什么我收到消息"非虚拟(在VB中可覆盖)成员上的无效设置..."?

我有一个单元测试,我必须模拟一个返回bool类型的非虚方法

public class XmlCupboardAccess
{
    public bool IsDataEntityInXmlCupboard(string dataId,
                                          out string nameInCupboard,
                                          out string refTypeInCupboard,
                                          string nameTemplate = null)
    {
        return IsDataEntityInXmlCupboard(_theDb, dataId, out nameInCupboard, out refTypeInCupboard, nameTemplate);
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我有一个XmlCupboardAccess类的模拟对象,我试图在我的测试用例中为这个方法设置mock,如下所示

[TestMethod]
Public void Test()
{
    private string temp1;
    private string temp2;
    private Mock<XmlCupboardAccess> _xmlCupboardAccess = new Mock<XmlCupboardAccess>();
    _xmlCupboardAccess.Setup(x => x.IsDataEntityInXmlCupboard(It.IsAny<string>(), out temp1, out temp2, It.IsAny<string>())).Returns(false); 
    //exception is thrown by this line of code
}
Run Code Online (Sandbox Code Playgroud)

但是这条线引发了异常

Invalid setup on a non-virtual (overridable in VB) member: 
x => x.IsDataEntityInXmlCupboard(It.IsAny<String>(), …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing moq

163
推荐指数
4
解决办法
13万
查看次数

jQuery hasClass() - 检查多个类

附:

if(element.hasClass("class"))
Run Code Online (Sandbox Code Playgroud)

我可以检查一个类,但有一个简单的方法来检查"元素"是否有任何类?

我在用:

if(element.hasClass("class") || element.hasClass("class") ... )
Run Code Online (Sandbox Code Playgroud)

这不是太糟糕,但我想的是:

if(element.hasClass("class", "class2")
Run Code Online (Sandbox Code Playgroud)

遗憾的是,这不起作用.

有类似的东西吗?

performance jquery jquery-selectors

153
推荐指数
5
解决办法
14万
查看次数

OSError:[Errno 2]在Django中使用python子进程时没有这样的文件或目录

我试图运行一个程序在Python代码中进行一些系统调用subprocess.call(),这会引发以下错误:

Traceback (most recent call last):
      File "<console>", line 1, in <module>
      File "/usr/lib/python2.7/subprocess.py", line 493, in call
      return Popen(*popenargs, **kwargs).wait()
      File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
      File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
      raise child_exception
      OSError: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)

我的实际Python代码如下:

url = "/media/videos/3cf02324-43e5-4996-bbdf-6377df448ae4.mp4"
real_path = "/home/chanceapp/webapps/chanceapp/chanceapp"+url
fake_crop_path = "/home/chanceapp/webapps/chanceapp/chanceapp/fake1"+url
fake_rotate_path = "/home/chanceapp/webapps/chanceapp.chanceapp/fake2"+url
crop = "ffmpeg -i %s -vf "%(real_path)+"crop=400:400:0:0 "+ "-strict -2 %s"%(fake_crop_path)
rotate = "ffmpeg -i %s -vf "%(fake_crop_path)+"transpose=1 "+"%s"%(fake_rotate_path)
move_rotated …
Run Code Online (Sandbox Code Playgroud)

python django subprocess

124
推荐指数
3
解决办法
15万
查看次数

如何将Django QuerySet转换为列表

我有以下内容:

answers = Answer.objects.filter(id__in=[answer.id for answer in answer_set.answers.all()])
Run Code Online (Sandbox Code Playgroud)

然后:

for i in range(len(answers)):
    # iterate through all existing QuestionAnswer objects
    for existing_question_answer in existing_question_answers:
        # if an answer is already associated, remove it from the
        # list of answers to save
        if answers[i].id == existing_question_answer.answer.id:
            answers.remove(answers[i])           # doesn't work
            existing_question_answers.remove(existing_question_answer)
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

'QuerySet' object has no attribute 'remove'
Run Code Online (Sandbox Code Playgroud)

我已经尝试了各种将QuerySet转换为标准集或列表.什么都行不通.

如何从QuerySet中删除一个项目,以便它不会从数据库中删除它,并且不会返回一个新的QuerySet(因为它在一个不起作用的循环中)?

django

107
推荐指数
8
解决办法
17万
查看次数

如何在Angular Material中使用<md-icon>?

我想知道如何使用Material的图标,因为这不起作用:

<material-icon icon = "/img/icons/ic_access_time_24px.svg"> </material-icon> 
Run Code Online (Sandbox Code Playgroud)

我想作为icon属性的参数给出的路径存在问题.我想知道这个图标文件夹到底在哪里?

angularjs material-design angularjs-material

102
推荐指数
5
解决办法
12万
查看次数

回滚失败的Rails迁移

如何回滚失败的rails迁移?我希望这rake db:rollback会撤消失败的迁移,但不会,它会回滚先前的迁移(失败的迁移减去一次).而且rake db:migrate:down VERSION=myfailedmigration也不起作用.我已经碰到了几次,这非常令人沮丧.这是我为复制问题所做的简单测试:

class SimpleTest < ActiveRecord::Migration
  def self.up
    add_column :assets, :test, :integer
    # the following syntax error will cause the migration to fail
    add_column :asset, :test2, :integer
  end

  def self.down
    remove_column :assets, :test
    remove_column :assets, :test2
  end
end
Run Code Online (Sandbox Code Playgroud)

结果:

==  SimpleTest: migrating =====================================================
-- add_column(:assets, :test, :integer)
   -> 0.0932s
-- add_column(:asset, :error)
rake aborted!
An error has occurred, all later migrations canceled:

wrong number of arguments (2 for 3)

好吧,让我们回滚:

$ rake db:rollback
== …

mysql ruby-on-rails rails-migrations rails-activerecord

80
推荐指数
6
解决办法
4万
查看次数

如何使用数组中的select包含psql中的value子句

我有arr 类型的列array.

我需要获取行,其中arr列包含值s

这个查询:

SELECT * FROM table WHERE arr @> ARRAY['s']
Run Code Online (Sandbox Code Playgroud)

给出错误:

错误:运算符不存在:字符变化[] @> text []

为什么不起作用?

ps我知道any()运算符,但为什么不@>工作?

postgresql postgresql-9.2

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