草庐IT

Current_Output

全部标签

python - 'IOError : [Errno 5] Input/output error' while using SMBus for analog reading through RPi

我一直在寻找标题中提到的错误的答案,但我还是第一次得到答案。我们将尝试让我的Raspberrypi读取模拟数据,但是当我在终端窗口中运行代码时,它给了我“IOError:[Errno5]Input/outputerror”。我用来读取模拟数据的代码如下所示。我使用PCF8591ADC转换器。fromsmbusimportSMBusbus=SMBus(0)print"reada/dpressctrl+ctostop"bus.write_byte(0x48,0)lastval=-1whileTrue:reada=bus.read_byte(0x48)if(abs(lastval-reada

Python 子进程 .check_call 与 .check_output

我的python脚本(python3.4.3)通过子进程调用bash脚本:importsubprocessasspres=sp.check_output("bashscript",shell=True)bashscript包含以下行:ssh-MNfsomehost它打开一个到某个远程主机的共享主连接以允许一些后续操作。在执行python脚本时,它会提示输入ssh行的密码,但是输入密码后它会阻塞并且永远不会返回。当我ctrl-C终止脚本时,我看到连接已正确建立(因此ssh行已成功执行)。我在使用check_call而不是check_output时没有这个阻塞问题,但是check_call

python - ipython : get access to current figure()

我想在绘制的图形上添加更细粒度的网格。问题是所有示例都需要访问Axis对象。我想将特定的网格添加到已经绘制的图形中(从ipython内部)。如何在ipython中访问当前图形和Axis? 最佳答案 plt.gcf()获取当前图形plt.gca()获取当前坐标Axis 关于python-ipython:getaccesstocurrentfigure(),我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/

python - 如何?时区 'UTC' 的 CURRENT_TIMESTAMP

我将如何修改我的调用sqlalchemy.func.current_timestamp()产生的东西CURRENT_TIMESTAMPATTIMEZONE'UTC' 最佳答案 快速解决方法是执行以下操作:func.current_timestamp().op('ATTIMEZONE')('UTC')更合适的方法是使用compiler扩展并定义CURRENT_TIMESTAMP的自定义编译。其实已经有example了在其文档中,它使用了不同的方法(TIMEZONE函数)。由于您只需要Postgres(我从您以前在SA邮件列表中的电子邮

python - 在 subprocess.check_output() 中抑制 stderr

我正在尝试寻找一种方法来忽略标准错误流(类似于2>/dev/null):output=subprocess.check_output("netstat-nptl".split())我应该在上面的命令中添加什么来实现这一点? 最佳答案 只需告诉subprocess为您重定向它:importsubprocessoutput=subprocess.check_output("netstat-nptl".split(),stderr=subprocess.DEVNULL)对于python2,它有点冗长。importosimportsubpr

Python Pandas : output dataframe to csv with integers

我有一个希望导出到CSV文件的pandas.DataFrame。但是,pandas似乎将一些值写为float而不是int类型。我找不到如何改变这种行为。构建数据框:df=pandas.DataFrame(columns=['a','b','c','d'],index=['x','y','z'],dtype=int)x=pandas.Series([10,10,10],index=['a','b','d'],dtype=int)y=pandas.Series([1,5,2,3],index=['a','b','c','d'],dtype=int)z=pandas.Series([1,2,

python - 将数据传递给 subprocess.check_output

我想调用一个脚本,将字符串的内容传送到它的标准输入并检索它的标准输出。我不想接触真正的文件系统,所以我不能为它创建真正的临时文件。使用subprocess.check_output我可以得到脚本所写的任何内容;我怎样才能把输入字符串放到它的标准输入中呢?subprocess.check_output([script_name,"-"],stdin="thisissomeinput")Traceback(mostrecentcalllast):File"",line1,inFile"/usr/lib/python2.7/subprocess.py",line537,incheck_out

Python argparse : Lots of choices results in ugly help output

我有这段代码,我通常很满意:importargparseservers=["ApaServer","BananServer","GulServer","SolServer","RymdServer","SkeppServer","HavsServer","PiratServer","SvartServer","NattServer","SovServer"]parser=argparse.ArgumentParser(description="Aprogramtoupdatecomponentsonservers.")group=parser.add_mutually_exclusiv

python - PyDev 单元测试 : How to capture text logged to a logging. 记录器在 "Captured Output"

我正在使用PyDev对我的Python应用程序进行开发和单元测试。至于单元测试,除了没有内容被记录到日志框架之外,一切都很好。PyDev的“捕获的输出”没有捕获记录器。我已经将记录的所有内容转发到标准输出,如下所示:importsyslogger=logging.getLogger()logger.level=logging.DEBUGlogger.addHandler(logging.StreamHandler(sys.stdout))尽管如此,“捕获的输出”不显示记录到记录器的内容。这是一个单元测试脚本示例:test.pyimportsysimportunittestimportl

python - subprocess.check_output() 似乎不存在(Python 2.6.5)

我一直在阅读有关subprocess模块的Python文档(参见here),其中谈到了subprocess.check_output()似乎正是我需要的命令。但是,当我尝试使用它时,我得到一个它不存在的错误,当我运行dir(subprocess)时它没有列出。我运行的是Python2.6.5,我使用的代码如下:importsubprocesssubprocess.check_output(["ls","-l","/dev/null"])有人知道为什么会这样吗? 最佳答案 它是在2.7中引入的,参见docs.使用subprocess.