草庐IT

read_exif_data

全部标签

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 - pyodbc.错误 : ('IM002' , '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)' )

我正在尝试使用pyodbc连接到数据库并遇到以下错误,有人可以建议如何克服以下错误吗?使用以下命令安装pyodbcsudoapt-getinstallunixodbc-devpipinstallpyodbc代码:-#!/usr/bin/pythonimportpyodbcserver_name='odsdb.qualcomm.com'database_name='ODS'#cnx=pyodbc.connect("SERVER="+server_name+";DATABASE="+database_name)cnx=pyodbc.connect("DRIVER={SQLServer};S

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 - 使用 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 - PyCharm (1.5.4) 和 Pandas 0.6.0 - ImportError : No module named data

我在MacOS10.6.4上使用PyCharm(1.5.4)作为我的pythonIDE。我正在修改一些代码来操纵股价数据。作为其中的一部分,我想使用Pandas0.6.0附带的DataReader函数从雅虎导入价格数据。代码如下:http://www.statalgo.com/2011/09/08/pandas-getting-financial-data-from-yahoo-fred-etc/frompandasimportols,DataFramefrompandas.stats.momentsimportrolling_stdfrompandas.io.dataimportDa

sys.stdin.read() 之后的 Python raw_input 抛出 EOFError

有人问过类似的问题before,但答案提出了一种不适用于我的情况的解决方法。电子邮件消息从mutt传送到脚本,并从STDIN读取:message=sys.stdin.read()#messageisparsedandURLsareprintedasalisttochoosefrom...selected_index=raw_input('WhichURLtoopen?')我知道raw_input()会得到read()留下的EOF,但是有没有办法“重置”STDIN? 最佳答案 你试过这个吗:message=sys.stdin.read

python - 使用pandas.read_csv从csv文件加载数据时如何指定dtype?

我有一些格式如下的文本文件:000423|东阿阿胶|300|1|0.15000||000425|徐工机械|600|1|0.15000||000503|海虹控股|400|1|0.15000||000522|白云山A||2||1982.080|000527|美的电器|900|1|0.15000||000528|柳工|300|1|0.15000||当我使用read_csv将它们加载到DataFrame时,它​​不会为某些列生成正确的数据类型。例如,第一列被解析为int,而不是unicodestr,第三列被解析为unicodestr,而不是int,因为缺少一个数据......有没有办法预设Da

python - SQS : How can I read the sent time of an SQS message using Python's boto library

当我在AWS控制台的SQS消息View中查看消息时,我可以看到消息有发送时间。我如何使用Python的boto库读取这些数据? 最佳答案 当您在boto中从队列中读取消息时,您会得到一个Message对象。该对象具有名为attributes的属性。它是SQS保留的关于此消息的属性字典。它包括SentTimestamp。 关于python-SQS:HowcanIreadthesenttimeofanSQSmessageusingPython'sbotolibrary,我们在StackOve

python - 在 python setup.py data_files 中包含整个目录

设置的data_files参数采用以下格式输入:setup(...data_files=[(target_directory,[listoffilestobeputthere])]....)有没有一种方法可以让我指定整个数据目录,这样我就不必单独命名每个文件并在我更改项目中的实现时更新它?我尝试使用os.listdir(),但我不知道如何使用相对路径,我不能使用os.getcwd()或os.realpath(__file__)因为它们没有正确指向我的存储库根目录。 最佳答案 karelv的想法是正确的,但要更直接地回答所述问题:fr

python - seek(),然后是 read(),然后是 python 中的 write()

当运行以下python代码时:>>>f=open(r"myfile.txt","a+")>>>f.seek(-1,2)>>>f.read()'a'>>>f.write('\n')我得到以下(有用的)异常:Traceback(mostrecentcalllast):File"",line1,inIOError:[Errno0]Error用“r+”打开时会发生同样的事情。这应该会失败吗?为什么?编辑:显然,这只是一个示例,并不是我实际要执行的操作。我的实际目标是在添加新行之前验证文件是否以“\n”结尾或添加一个。我在WindowsXP下工作,Python2.5和Python2.6都存在问题