小编A.J*_*pal的帖子

iOS中UITableView的UISearchDisplayController框架

  • 我有UITable一个UISearchDisplayController.
  • UITable是小于屏幕的宽度(它是280像素宽度居中).
  • 当我点击时search bar,UISearchDisplayController表格一直到屏幕的左边.
  • 即使改变桌子的框架UISearchDisplayController,我仍然得到相同的定位.

我在这里设置框架:

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView  {
    tableView.backgroundColor = [UIColor colorWithRed:29.0/255.0 green:30.0/255.0 blue:32.0/255.0 alpha:1];
    tableView.rowHeight = self.myTable.rowHeight;
    tableView.frame = myTable.frame;
    NSLog(@"search table origin: %f",tableView.frame.origin.x);
}
Run Code Online (Sandbox Code Playgroud)

甚至更奇怪的是,当我在最后记录搜索表位置时,它显示16.但是,它在视图中的位置0处.

任何帮助表示赞赏.

iphone uisearchbar uisearchdisplaycontroller ios

4
推荐指数
1
解决办法
5516
查看次数

Flask self.errors.append() - AttributeError:'tuple'对象没有属性'append'

当我尝试用户验证提交的数据并检查输入的电子邮件是否存在时,我的小注册应用程序给出错误.

这是我的文件:
表格:

from flask.ext.wtf import Form
from wtforms import TextField, BooleanField, PasswordField, TextAreaField, validators
from wtforms.validators import Required
from app import models

class RegisterForm(Form):
"""RegisterForm class needed for retrieving data from user"""
username = TextField('username', [validators.Length(min=3, max=50), validators.Required()])
email = TextField('email', [validators.Length(min=3, max=100), validators.Required()])
password = PasswordField('password', [validators.Required()])
age = TextField('age', [validators.Length(min=1, max=3), validators.Required()])
about_user = TextAreaField('about_user', [validators.Length(max=500)])
img_url = TextField('img_url')


def email_unique(self, email):
    if models.User.query.filter_by(email = email).first() != None:
        self.email.errors.append('This E-mail address is already in use. Please choose …
Run Code Online (Sandbox Code Playgroud)

python django flask flask-wtforms

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

如何获得字符串的所有子串的每一个排列?

我知道如何在python中获得纯字符串的排列:

>>> from itertools import permutations
>>> perms = [''.join(p) for p in permutations('stack')]
>>> print perms
...
Run Code Online (Sandbox Code Playgroud)

但是,我怎么会得到的排列'stac','stak','sack','stck','stc','st',等等?我想要的输出是:

>>> permutations('pet')
['pet', 'pte', 'ept', 'etp', 'tpe', 'tep', 'pe', 'ep', 'p', 'e', 't', 'pt', 'tp', 'et', 'te']
Run Code Online (Sandbox Code Playgroud)

到目前为止我所拥有的:

def permutate(values, size):
  return map(lambda p: [values[i] for i in p], permutate_positions(len(values), size))

def permutate_positions(n, size):
  if (n==1):
    return [[n]]
  unique = []
  for p in map(lambda perm: perm[:size], [ p[:i-1] …
Run Code Online (Sandbox Code Playgroud)

python string algorithm substring permutation

4
推荐指数
1
解决办法
204
查看次数

TypeError:在字符串格式化错误python期间并非所有参数都被转换

我为我们的REST API定制了暴风代码,但是当我运行脚本时,在开头使用nosetests会产生一些奇怪的类型错误,如下所述,尽管脚本中的测试用例通过

Traceback (most recent call last):
  File "/usr/lib64/python2.6/logging/__init__.py",line 776, in emit msg = self.format(record)
  File "/usr/lib64/python2.6/logging/__init__.py", line 654, in format return fmt.format(record)
  File "/home/rmcbuild/repository/rmc-test/tempest/openstack/common/log.py", line 516, in format return logging.Formatter.format(self, record)
  File "/usr/lib64/python2.6/logging/__init__.py", line 436, in format record.message = record.getMessage()
  File "/usr/lib64/python2.6/logging/__init__.py", line 306, in getMessage msg = msg % self.args
 TypeError: not all arguments converted during string formatting
Run Code Online (Sandbox Code Playgroud)

有没有人遇到过这种类型的错误,如果有人帮助我,我会很感激.

谢谢,

python

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

为什么\*即使是原始字符串也会逃脱?

我已经读过,当存在'r'前缀时,字符串中包含反斜杠后面的字符没有更改,并且所有反斜杠都保留在字符串中.但是当我创建一个正则表达式对象时:p=re.compile(r'\*(.*?)\*')它匹配'*text*'.我不明白为什么会这样.根据我的印象,它应该匹配'\*text\*'.

python regex

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

我如何在python中发送电子邮件?此代码无效

import smtplib
#SERVER = "localhost"

FROM = 'monty@python.com'

TO = ["jon@mycompany.com"] # must be a list

SUBJECT = "Hello!"

TEXT = "This message was sent with Python's smtplib."

# Prepare actual message

message = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

# Send the mail

server = smtplib.SMTP('myserver')
server.sendmail(FROM, TO, message)
server.quit()
Run Code Online (Sandbox Code Playgroud)

当我尝试在终端中的python shell中运行它时,它给了我这个错误:

Traceback (most recent call last):
    File "email.py", line 1, in <module>
        import smtplib
    File "/usr/lib/python2.7/smtplib.py", line 46, in …
Run Code Online (Sandbox Code Playgroud)

python email smtp attributeerror python-2.7

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

我可以将 jQuery 与 Javascript 结合使用吗?

我想使用JavaScript选择document.querySelectorinsted的的$jQueryjQuery选择,但我想给Javascript选择使用jQuery函数(如合并.getJSON().html().append(),等)。

例如:

$.getJSON("list.json", function(data) {
    document.querySelector("#content").html(data.name);
});
Run Code Online (Sandbox Code Playgroud)

在这里,当我使用document.querySelector我得到的Uncaught TypeError: undefined is not a function,当我使用$我没有得到任何错误。

jsFiddle Test

是否可以同时运行 jQuery 和 Javascript?

谢谢!

javascript jquery

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

Python'long'对象没有'to_bytes'属性?

我试图使用从Python编写的一个比特币地址验证在这里:

这个片段给我带来了麻烦:

def decode_base58(bc, length):
    n = 0
    for char in bc:
        n = n * 58 + digits58.index(char)
    return n.to_bytes(length, 'big')
Run Code Online (Sandbox Code Playgroud)

我知道n是int或long,但是没有一个名为to_bytes的方法,所以我真的不明白这段代码是如何工作的?

有人知道这里有什么问题吗?我做错了什么,或者这个代码只是写错了?欢迎所有提示!

python long-integer

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

用python中的AES生产ECB企鹅

我想加密图像中的数据,但生成的密文仍然是有效的图像.我在python中使用AES加密图像然后,我替换文件中的标头,但是窗口无法打开加密图像.

def encrypt_file(self, in_filename, out_filename):
    filesize = os.path.getsize(in_filename)
    iv = Random.new().read(AES.block_size)
    cipher = AES.new(self.key, AES.MODE_ECB, iv)
    chunksize = 64 * 1024
    with open(in_filename, 'rb') as infile:
        with open(out_filename, 'wb') as outfile:
            outfile.write(struct.pack('<Q', filesize))
            outfile.write(iv)

            while True:
                chunk = infile.read(chunksize)
                if len(chunk) == 0:
                    break
                elif len(chunk) % 16 != 0:
                    chunk += ' ' * (16 - len(chunk) % 16)
                cifrado = base64.b64encode(cipher.encrypt(chunk))
                print cifrado
                outfile.write(cipher.encrypt(chunk))
Run Code Online (Sandbox Code Playgroud)

我想要这个效果: 欧洲央行企鹅

python encryption image aes ecb

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

获取多个列表共有的字符串元素的索引

我想获得多个列表共有的字符串元素的索引.只有'狗'和'斑马'分别对于两个(A和B)和三个列表(A,B和C)是共同的.

A = ['apple','banana','dog','fig','zebra']
B = ['zebra','avocado','dog','egg','corn']
C = ['egg','guava','zebra','carrot','beans']
Run Code Online (Sandbox Code Playgroud)

预期的答案是:

A[2] A[4] B[0] B[2] B[3] C[0] C[2]
Run Code Online (Sandbox Code Playgroud)

我想用干净简单的方法来实现它.

python

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