Why are postscript files created in a Python directory?

I have a python script that imports some Python modules like bs4 , json , os , requests , signal , sys and time . Sometimes I see the following files in my 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 Postscript files. For example:

 $ 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 have never run anything related to Postscript in this directory. Moreover, even if I rm files, they seem to come back after a while, so something creates them periodically. When I see that they have the same names as the Python modules imported into the Python script in this directory, I suspect a correlation. What could be the reason?

+8
python postscript
source share
1 answer

I'll take a hit on this ... It seems like I sometimes see it when I accidentally call a script without specifying a Python interpreter, for example. I say ./foo.py instead of python foo.py or does not have the line #! at the beginning of the script. When I do this, the script will end with a syntax error, and the directory will be filled with files named sys, os, time, et al - these are the modules that I imported in my script. These new files are quite large (7 MB). Running head sys shows the contents of the file are essentially the same as yours. I use Linux (Ubuntu) and not an IDE for my Python development, but only a bash shell.

Here is what I think happens, at least in Linux: if you do man import , you will see

import - saves any visible window on the X server and displays it as an image file. You can capture one window, the entire screen or any rectangular part of the screen.

[...]

The import program is part of the ImageMagick toolkit (1). Use it to capture some or all of the X server screens and save the image to a file.

So, I assume that the shell interprets the first line of Python import statements as /usr/bin/import and uses the "argument" (module name) as the name of the image file to save. Therefore, the PS / ImageMagick material is at the top of the file.

Again, I only see this if I sometimes select and invoke a script without a Python interpreter. Since I don’t know your code or terms of use, I cannot guarantee that this is your exact problem, but I assume that you are doing something similar (perhaps unknowingly). Hope this helps and you get on the right track.

EDIT: Here's an experiment that basically reproduces your problem. The code:

 import sys import random import os import time import signal def main(): sys.stdout.write('foo\n') if (__name__ == "__main__"): main() 

I call it without Python:

 ./foo.py ./foo.py: line 8: syntax error near unexpected token `(' ./foo.py: line 8: `def main():' 

New files appeared:

 $ 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 their contents:

 $ 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.

+15
source share

All Articles