[英]Why are postscript files being created in Python directory?
I have a python script which imports some Python modules, such as bs4
, json
, os
, requests
, signal
, sys
, and time
. 我有一个python脚本,它导入一些Python模块,如
bs4
, json
, os
, requests
, signal
, sys
和time
。 Sometimes I notice in my PWD the following files: 有时我在PWD中注意到以下文件:
$ ls -la
-rw-rw-r-- 1 dotancohen dotancohen 12429677 Jun 26 11:37 bs4
-rw-rw-r-- 1 dotancohen dotancohen 12291853 Jun 26 11:36 json
-rwxrwxr-x 1 dotancohen dotancohen 1681 Jun 26 11:51 my-app.py
-rw-rw-r-- 1 dotancohen dotancohen 12291851 Jun 26 11:36 os
-rw-rw-r-- 1 dotancohen dotancohen 12291855 Jun 26 11:36 random
-rw-rw-r-- 1 dotancohen dotancohen 12291851 Jun 26 11:36 re
-rw-rw-r-- 1 dotancohen dotancohen 12429682 Jun 26 11:38 requests
-rw-rw-r-- 1 dotancohen dotancohen 7216 Jun 26 11:38 signal
-rw-rw-r-- 1 dotancohen dotancohen 12291852 Jun 26 11:36 sys
-rw-rw-r-- 1 dotancohen dotancohen 12429678 Jun 26 11:36 time
However, these are not Python files but rather seem to be Postscript files. 但是,这些不是Python文件,而是似乎是Postscript文件。 For instance:
例如:
$ file sys
sys: PostScript document text conforming DSC level 3.0, Level 1
$ head sys
%!PS-Adobe-3.0
%%Creator: (ImageMagick)
%%Title: (sys)
%%CreationDate: (2013-06-26T11:36:13+03:00)
%%BoundingBox: -0 -0 1920 1053
%%HiResBoundingBox: 0 0 1920 1053
%%DocumentData: Clean7Bit
%%LanguageLevel: 1
%%Orientation: Portrait
%%PageOrder: Ascend
I've never run anything related to Postscript in this directory. 我从未在此目录中运行与Postscript相关的任何内容。 Furthermore, even if I
rm
the files they seem to come back after some time, so something in periodically creating them. 此外,即使我
rm
文件,他们似乎来到了一段时间后回来,所以事情在定期创建它们。 Seeing as they have the same names as the Python modules being imported in the Python script in this directory, I suspect correlation. 看到它们与在此目录中的Python脚本中导入的Python模块具有相同的名称,我怀疑它是相关的。 What could be the cause?
可能是什么原因?
I'll take a stab at this... This looks like something I see sometimes when I accidentally invoke a script without specifying a Python interpreter, eg I say ./foo.py
instead of python foo.py
, or do not have a #!
我会对此进行一次尝试...这看起来像我有时在没有指定Python解释器时调用脚本时看到的东西,例如我说
./foo.py
而不是python foo.py
,或者没有#!
line at the script's beginning. 在脚本的开头。 When I do this, the script fails after some time with a syntax error, and the directory is filled with files named sys, os, time, et al -- exactly the modules I was importing in my script.
当我这样做时,脚本在语法错误一段时间后失败,并且目录中填充了名为sys,os,time 等的文件 - 正是我在脚本中导入的模块。 These new files are fairly large (7MB).
这些新文件相当大(7MB)。 Doing
head sys
shows file contents essentially the same as yours. 执行
head sys
显示文件内容与您的文件内容基本相同。 I use Linux (Ubuntu) and no IDE for my Python development, just a bash shell. 我使用Linux(Ubuntu)而没有IDE用于我的Python开发,只是一个bash shell。
Here's what I think is going on, at least on Linux: If you do man import
you'll see 这是我认为正在发生的事情,至少在Linux上:如果你
man import
你会看到
import - saves any visible window on an X server and outputs it as an image file.
import - 将任何可见窗口保存在X服务器上并将其作为图像文件输出。 You can capture a single window, the entire screen, or any rectangular portion of the screen.
您可以捕获单个窗口,整个屏幕或屏幕的任何矩形部分。
[...]
[...]
The import program is a member of the ImageMagick(1) suite of tools.
导入程序是ImageMagick(1)工具套件的成员。 Use it to capture some or all of an X server screen and save the image to a file.
使用它来捕获部分或全部X服务器屏幕并将图像保存到文件中。
So I'm guessing that the shell is interpreting the first line of Python import
statements as the /usr/bin/import
command, and using the "argument" (module name) as the name of the image file to save. 所以我猜测shell将第一行Python
import
语句解释为/usr/bin/import
命令,并使用“argument”(模块名称)作为要保存的图像文件的名称。 Hence the PS / ImageMagick stuff at the top of the file. 因此PS / ImageMagick的东西位于文件的顶部。
Again, I only see this when I occasionally space out and invoke my script with no Python interpreter. 再一次,我只是在偶尔空出并调用没有Python解释器的脚本时才看到这个。 Since I don't know your code or usage conditions I can't guarantee this is your exact issue, but I'm guessing you're doing something similar (maybe unknowingly).
由于我不知道您的代码或使用条件,我无法保证这是您的确切问题,但我猜您正在做类似的事情(可能是在不知不觉中)。 I hope this helps, and gets you on the right track.
我希望这会有所帮助,让你走上正轨。
EDIT: Here's an experiment which basically reproduces your issue. 编辑:这是一个基本上再现您的问题的实验。 Code:
码:
import sys
import random
import os
import time
import signal
def main():
sys.stdout.write('foo\n')
if (__name__ == "__main__"):
main()
I invoke it with no Python: 我没有Python调用它:
./foo.py
./foo.py: line 8: syntax error near unexpected token `('
./foo.py: line 8: `def main():'
New files are there: 有新文件:
$ ls
total 25096
-rwxr-xr-x 1 doug doug 146 2013-06-27 10:31 foo.py
-rw-r--r-- 1 doug doug 7291759 2013-06-27 10:12 os
-rw-r--r-- 1 doug doug 7291763 2013-06-27 10:12 random
-rw-r--r-- 1 doug doug 1903418 2013-06-27 10:32 signal
-rw-r--r-- 1 doug doug 1903415 2013-06-27 10:32 sys
-rw-r--r-- 1 doug doug 7291761 2013-06-27 10:12 time
Look at the contents of them: 看看它们的内容:
$ head sys
%!PS-Adobe-3.0
%%Creator: (ImageMagick)
%%Title: (sys)
%%CreationDate: (2013-06-27T10:32:20-05:00)
%%BoundingBox: 0 0 663 471
%%HiResBoundingBox: 0 0 663 471
%%DocumentData: Clean7Bit
%%LanguageLevel: 1
%%Orientation: Portrait
%%PageOrder: Ascend
Again, I hope this sheds some light and helps a bit. 再次,我希望这会有所帮助,并有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.