小编ych*_*che的帖子

Mako或Jinja2?

我没有找到jinja2和Mako的良好比较.你会用什么来完成什么任务?

我个人很满意mako(在一个pylons网络应用程序环境中),但我很想知道jinja2是否有一些很好的功能/改进mako不? - 或者可能是缺点? -

python templates template-engine mako jinja2

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

跳转到emacs中的函数开头

所以你正处于300行函数的中间,并想知道函数声明的位置.

你怎么做到这一点?

emacs

10
推荐指数
2
解决办法
1517
查看次数

将参数传递给psql.exe

我想从应用程序启动psql.exe.用户找到脚本,因此它可以在他的磁盘上的任何位置,并且应用程序只是将该脚本提供给psql.就是这样.

什么是正确的命令行?

我试过这个没有成功

"C:\Program Files\PostgreSQL\9.1\bin\psql.exe" TEST SYSADM -f "C:\Documents and Settings\Administrateur\Mes documents\TD6.0\FETCHING\install.sql"
Run Code Online (Sandbox Code Playgroud)

我尝试使用引号,没有引号,没有工作,只是忽略了参数(在cmd.exe上试过)

C:\Documents and Settings\Administrateur>"C:\Program Files\PostgreSQL\9.1\bin\psql.exe" TEST SYSADM -f "C:\Documents and Settings\Administrateur\Mes documents\TD6.0\FETCHING\install.
sql"
psql: warning: extra command-line argument "-f" ignored
psql: warning: extra command-line argument "C:\Documents and Settings\Administrateur\Mes documents\TD6.0\FETCHING\install.sql" ignored
Password for user SYSADM:
Run Code Online (Sandbox Code Playgroud)

是的,如果脚本与psql.exe位于同一目录中,并且如果我首先将CD安装到安装psql.exe的位置,则表示没有引号,没有绝对路径,并且它可以正常工作.但是,在我的情况下,我希望应用程序可以在任何Windows安装上工作,这意味着psql.exe可以在任何地方,sql脚本也可以在任何地方.我仍然希望将脚本提供给psql.exe.

windows postgresql

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

SQLAlchemy可以更新表结构吗?

我正在研究我的第一个挂架+ SQLAlchemy应用程序(我是两个都是新手).

当我改变对表结构的看法时,我希望有一个类似于metadata.create_all()的函数,它检查是否有新的列定义并在数据库中创建它们.

这样的功能存在吗?

python mysql pylons sqlalchemy

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

7
推荐指数
2
解决办法
3746
查看次数

为什么object .__ new__在这三种情况下的工作方式不同

来自问题为什么或者更确切地说对象.__ new__在这两种情况下的工作方式不同

作者对其原因不感兴趣,而是对其如何感兴趣.

我非常想了解原因,特别是:

  1. 为什么不object.__init__打印参数而不是object.__new__ (in testclass1)

  2. 为什么没有为testclass3引发错误?(因为除了自我之外不需要任何参数)

>>> class testclass1(object):
    ...     pass
    ... 

>>> class testclass2(object):
    ...     def __init__(self,param):
    ...             pass
    ... 

>>> a = object.__new__(testclass1, 56)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: object.__new__() takes no parameters

>>> b = object.__new__(testclass2, 56)

>>> b
    <__main__.testclass2 object at 0x276a5d0>

>>> class testclass3(object):
    ...     def __init__(self):
    ...             pass
    ... 

>>> c = object.__new__(testclass3, 56)

>>> c
    <__main__.testclass3 object at 0x276a790> …
Run Code Online (Sandbox Code Playgroud)

python constructor types object

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

使用cmd python模块时,如何使程序正常崩溃?

会发生的是,如果您的代码引发运行时异常并且您的完成不起作用,您就不知道为什么因为没有打印回溯.试试这个非常短的代码来看看我的意思:程序应该在c = 2 +"ddda"上崩溃,显然你要添加一个字符串和一个int,这根本不起作用.但是不是崩溃,而是异常被抓住了,你不知道发生了什么.该程序继续运行,好像什么也没发生.

import cmd

class App(cmd.Cmd):
    def complete_foo(self,*arg):
        # Uncommenting this line will silently crash the progrm
        # making it hard to debug.
        # Is there a way to force the program to crash ?
        c = 2 + "ddda"
        return "d dzpo idz dza dpaoi".split(" ")

    def do_foo(self,*args):
        print "foo"
App().cmdloop()
Run Code Online (Sandbox Code Playgroud)

我的问题是:当有错误时如何显示错误?(使用cmd模块时).

python cmd

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

如何在urwid中创建嵌套列表框?

是否可以将ListBoxes放在SimpleListWalkers中?我正在尝试制作嵌套的ListBoxes,但是我有这个错误:

AttributeError: 'MyListBox' object has no attribute 'rows'

import urwid

class MyListBox(urwid.ListBox):
    def focus_next(self):
        try: 
            self.body.set_focus(self.body.get_next(self.body.get_focus()[1])[1])
        except:
            pass
    def focus_previous(self):
        try: 
            self.body.set_focus(self.body.get_prev(self.body.get_focus()[1])[1])
        except:
            pass            

def handle_input(event):
    frame.header.set_text("key pressed %s" % event)
    if event == "q":
        raise urwid.ExitMainLoop
    elif event == "up":
        lb.focus_previous()
    elif event == "down" :
        lb.focus_next()        

widgets   = [urwid.AttrMap(urwid.Text(str(x)),None,"focus") for x in xrange(3)]
nested    = [urwid.AttrMap(urwid.Text(str(x)+"_sous"),None,"focus") for x in xrange(3)]
nested_lb = MyListBox(urwid.SimpleListWalker(nested))
lb        = MyListBox(urwid.SimpleListWalker(widgets+[nested_lb]))
frame     = urwid.Frame(lb,header=urwid.Text("Header"))
palette   = [("focus","dark cyan","white")]
loop      = urwid.MainLoop(frame,palette,unhandled_input = handle_input) …
Run Code Online (Sandbox Code Playgroud)

python nested listbox urwid

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

如何在 Tkinter 中垂直居中小部件?

此代码仅水平居中,如何使进度条也垂直居中?

import Tkinter
import ttk
root = Tkinter.Tk()
root.geometry("=500x500")
root.progressbar = ttk.Progressbar(root)
root.progressbar.pack(anchor=Tkinter.CENTER)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)

截屏

tkinter

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

PHP警告:PHP启动:第0行的Unknown中的库(可能不是PHP库)无效

想补充一下 GD zip扩展到php,完成了phpize ./configure make make install例程,还是找不到 GD压缩.任何的想法 ?

root@audio-mon[10.10.10.82] ~/DOWNLOADS/php-5.5.23/ext/zip # phpize 
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212
root@audio-mon[10.10.10.82] ~/DOWNLOADS/php-5.5.23/ext/zip # ./configure 
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking …
Run Code Online (Sandbox Code Playgroud)

php php-extension

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