草庐IT

read_file

全部标签

python PIL : Find the size of image without writing it as a file

编辑:这个问题被标记为重复?我的问题显然是关于优化这个过程,而不是如何去做。我什至提供了代码来证明我已经弄清楚了后者。在标记这些问题之前,您的互联网大厅监控器甚至会阅读标题后面的这些问题吗?我有以下代码块使用PIL压缩图像,直到所述图像小于特定大小。fromPILimportImageimportosdefcompress(image_file,max_size,scale):whileos.path.getsize(image_file)>max_size:pic=Image.open(image_file)original_size=pic.sizepic=pic.resize((

Python 和 Excel : Overwriting an existing file always prompts, 尽管 XlSaveConflictResolution 值

我正在使用Python程序中的Excel.ApplicationCOM对象打开CSV文件并将其另存为Excel工作簿。如果目标文件已存在,则会提示我此消息:“此位置已存在名为‘...’的文件。是否要替换它?”尽管我已经设置了XlSaveConflictResolution,但还是会出现该消息xlLocalSessionChanges的值,它应该在没有提示的情况下自动覆盖更改——我是这么认为的。我使用的是MicrosoftOfficeExcel2007(12.0.6535.5002)SP2MSO和ActivePython2.6.5.14。我已经使用常量和整数尝试了所有三个XlSaveCo

python - IO错误 : [Errno 2] No such file - Paramiko put()

我正在使用Paramiko通过SFTP上传文件使用sftp.put(localFile,remoteFile)。如果需要,我会先创建必要的目录makeCommand='mkdir-p"'+remotePath+'"'ssh.exec_command(makeCommand)这有时是有效的,但我偶尔会收到以下错误:sftp.put(localFile,remoteFile)File"build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py",line565,inputFile"build/bdist.macosx-10.8-int

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 - "The system cannot find the file specified"在 python 中调用 subprocess.Popen 时

我正在尝试使用svnmerge.py来合并一些文件。在引擎盖下它使用python,当我使用它时出现错误-“系统找不到指定的文件”。工作中的同事正在运行相同版本的svnmerge.py和python(2.5.2,特别是r252:60911),没有任何问题。我找到了thislink,它描述了我的问题。尝试那里概述的内容,我确认Python可以找到SVN(它在我的路径中):P:\>pythonPython2.5.2(r252:60911,Feb212008,13:11:45)[MSCv.131032bit(Intel)]onwin32Type"help","copyright","credi

python - 打印到 Python : redirect vs print's file argument vs write 中的文件

我有一堆print调用需要写入文件而不是stdout。(我根本不需要stdout。)我正在考虑三种方法。其中任何一个有什么优势(包括性能)吗?完全重定向,我看到了here:importsyssaveout=sys.stdoutfsock=open('out.log','w')sys.stdout=fsockprint(x)#andmanymoreprintcalls#laterifIeverneedit:#sys.stdout=saveout#fsock.close()在每个打印语句中重定向:fsock=open('out.log','w')print(x,file=fsock)#an

CMake file文件操作命令

使用cmake文件操作时不可避免需要操作相关文件,比如读取文件内容,创建新文件的等等操作,都需要通过file命令进行操作。读文件操作fileREAD命令常用的从文件中读取操作为file(READ),将filename文件中内容原封不动读取到variable变量中,命令行全部格式为:file(read[OFFSET][LIMIT][HEX])filename:必选项为要读取的文件,可以带绝对路径variable:必选项,将文件内容读取到varible变量中。OFFSET:可选项,从文件中偏移位置offset开始读取文件内容HEX:可选项,可以将读取文件内容转换成十六进制。用例LIMIT:可选项最

python 2.5.2 : trying to open files recursively

下面的脚本应该递归地打开“pruebaba”文件夹中的所有文件,但我收到此错误:Traceback(mostrecentcalllast):File"/home/tirengarfio/Desktop/prueba.py",line8,inf=open(file,'r')IOError:[Errno21]Isadirectory这是层次结构:pruebabafolder1folder11test1.phpfolder12test1.phptest2.phpfolder2test1.php脚本:importre,fileinput,ospath="/home/tirengarfio/De