草庐IT

create_proc_read_entry

全部标签

python - 将列表绑定(bind)到 Pandas read_sql_query 中的参数和其他参数

我一直在尝试测试使我的代码运行的各种方法。首先,我有这个列表:member_list=[111,222,333,444,555,...]我试图将它传递到这个查询中:query=pd.read_sql_query("""selectmemberid,yearmonthfromqueried_tablewhereyearmonthbetween?and?andmember_idin?""",db2conn,params=[201601,201603,member_list])但是,我收到一条错误消息:'Invalidparametertype.param-index=2param-type

python - Python io.BytesIO 的 write()、read() 和 getvalue() 方法如何工作?

我试图理解io.BytesIO的write()和read()方法。我的理解是我可以像使用文件一样使用io.BytesIO对象。importioin_memory=io.BytesIO(b'hello')print(in_memory.read())上面的代码将按预期返回b'hello',但下面的代码将返回一个空字符串b''。importioin_memory=io.BytesIO(b'hello')in_memory.write(b'world')print(in_memory.read())我的问题是:-io.BytesIO.write(b'world')到底在做什么?-io.Byt

Python 子进程交互,为什么我的进程使用 Popen.communicate 而不是 Popen.stdout.read()?

我正在尝试使用subprocess模块与使用Python的命令行聊天机器人进行通信。(http://howie.sourceforge.net/使用编译后的win32二进制文件,我有我的理由!)这个有效:proc=Popen('Howie/howie.exe',stdout=PIPE,stderr=STDOUT,stdin=PIPE)output=proc.communicate()但是Popen.communicate等待进程终止(并向其发送EOF?),我希望能够与其进行交互。明显的解决方案是像这样读取stdout/写入stdin:这行不通:proc=Popen('Howie/how

python - 获取模拟 file.read() 的实际返回值

我正在使用python-mock模拟文件打开调用。我希望能够以这种方式传递虚假数据,这样我就可以验证read()被调用以及使用测试数据,而不会在测试中访问文件系统。这是我到目前为止所得到的:file_mock=MagicMock(spec=file)file_mock.read.return_value='test'withpatch('__builtin__.open',create=True)asmock_open:mock_open.return_value=file_mockwithopen('x')asf:printf.read()这个输出是而不是'test'正如我所假设的那

python - Setuptools 不为 entry_points 传递参数

我正在为我编写的Python脚本使用setuptools安装后,我会:$megazord-iinput-ddatabase-vxx-xx-wyy-yy如果我正在运行它,我会这样做。/like_this但是,我得到:Traceback(mostrecentcalllast):File"/usr/local/bin/megazord",line9,inload_entry_point('megazord==1.0.0','console_scripts','megazord')()TypeError:main()takesexactly1argument(0given)看起来setupto

python - 子进程 popen.communicate() 与 stdin.write() 和 stdout.read()

我注意到两种不同的行为和两种方法应该会产生相同的结果。目标-使用subprocess模块执行外部程序,发送一些数据并读取结果。外部程序为PLINK,平台为WindowsXP,Python3.3版本。主要思想-execution=["C:\\Pr..\\...\\plink.exe","-l",username,"-pw","***",IP]a=subprocess.Popen(execution,bufsize=0,stdout=PIPE,stdin=PIPE,stderr=STDOUT,shell=False)con=a.stdout.readline()if(con.decode(

python - Python 中的 GTK3 对话框,Gtk.Entry 上的 "enter key"应该触发确定按钮

我使用Gtk3用Python编写了以下代码。fromgi.repositoryimportGtkclassDialogTaskDescription(Gtk.Dialog):def__init__(self):Gtk.Dialog.__init__(self,"CreateToDo.txtEntry",0,0,(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL,Gtk.STOCK_OK,Gtk.ResponseType.OK))self.set_default_size(150,100)hbox=Gtk.Box(orientation=Gtk.Orien

python - Openerp create() 方法返回新的记录集 ID 但不更新数据库

我正在OpenERP7中开发一个网络服务,它使用POST方法在res_partner表上创建一个新伙伴。我的问题是create()方法返回新的对象ID,但数据库没有更新。这是我的代码:@openerpweb.httprequestdefadd_partner(self,req,db,user,password,name,type,street,city,zip,phone,email,function):uid=req.session.authenticate(db,user,password)osv_pool=pooler.get_pool(db)cr=pooler.get_db(d

python - 使用 pandas.io.sql.read_frame,我可以像 read_csv 一样解析日期吗?

我正在使用pandas.io.sql.read_frame直接从数据库读取data_frame:cnx=pandas.io.sql.connect(host='srv',user='me',password='pw',database='db')df=pandas.io.sql.read_frame('sql_query',cnx)它可以很好地检索数据。但我想将其中一列解析为datetime64,类似于从CSV文件读取时可以执行的操作,例如:df2=pandas.io.read_csv(csv_file,parse_dates=[0])但是read_frame没有parse_dates

python : subclass `type` to create specialized types (e. g。一个 "list of int")

我正在尝试对type进行子类化,以创建一个允许构建专门类型的类。例如一个ListType:>>>ListOfInt=ListType(list,value_type=int)>>>issubclass(ListOfInt,list)True>>>issubclass(list,ListOfInt)False>>>#Andsoon...但是,这个ListOfInt永远不会被用来创建实例!我只是将它用作type的实例,我可以操纵它来与其他类型进行比较......特别是,在我的情况下,我需要根据类型查找合适的操作输入,我需要该类型包含更多精度(如listofint或XMLstring等...