Why the file mode of .pyc files has x?

P

Peng Yu

Hi,

It is strange that the file mode of .pyc files are changed to
executable (x mode) after the corresponding .py files have been run. I
have the follow python, which is compiled from source code by me.

$ python --version
Python 2.6.2

Should .pyc files have the x mode?

Regards,
Peng
 
S

Steven D'Aprano

Hi,

It is strange that the file mode of .pyc files are changed to executable
(x mode) after the corresponding .py files have been run.

Are you sure? They don't on my system.


[steve@sylar test]$ ls -l
total 8
-rw-rw-r-- 1 steve steve 6 2009-09-26 23:06 test.py
[steve@sylar test]$ python2.6 test.py
[steve@sylar test]$ ls -l
total 8
-rw-rw-r-- 1 steve steve 6 2009-09-26 23:06 test.py


Running a .py file does not generally create a .pyc file. Normally you
have to import it:

[steve@sylar test]$ python2.6
Python 2.6.1 (r261:67515, Dec 24 2008, 00:33:13)
[GCC 4.1.2 20070502 (Red Hat 4.1.2-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.[steve@sylar test]$ ls -l
total 16
-rw-rw-r-- 1 steve steve 6 2009-09-26 23:06 test.py
-rw-rw-r-- 1 steve steve 94 2009-09-26 23:08 test.pyc


Have you checked the umask of your system?
 
P

Peng Yu

Hi,

It is strange that the file mode of .pyc files are changed to executable
(x mode) after the corresponding .py files have been run.

Are you sure? They don't on my system.


[steve@sylar test]$ ls -l
total 8
-rw-rw-r-- 1 steve steve 6 2009-09-26 23:06 test.py
[steve@sylar test]$ python2.6 test.py
[steve@sylar test]$ ls -l
total 8
-rw-rw-r-- 1 steve steve 6 2009-09-26 23:06 test.py


Running a .py file does not generally create a .pyc file. Normally you
have to import it:

[steve@sylar test]$ python2.6
Python 2.6.1 (r261:67515, Dec 24 2008, 00:33:13)
[GCC 4.1.2 20070502 (Red Hat 4.1.2-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.[steve@sylar test]$ ls -l
total 16
-rw-rw-r-- 1 steve steve  6 2009-09-26 23:06 test.py
-rw-rw-r-- 1 steve steve 94 2009-09-26 23:08 test.pyc


Have you checked the umask of your system?

Here are my test case. If the .py file has the 'x' mode, the
corresponding .pyc file also has the 'x' mode after the .py file is
imported.

pengy@selenium:~/test/python/pyc_mode$ umask
0077
pengy@selenium:~/test/python/pyc_mode$ ll
total 8
-rw------- 1 pengy lilab 29 2009-09-26 10:10:45 main.py
-rwx------ 1 pengy lilab 106 2009-09-26 10:19:17 test.py
pengy@selenium:~/test/python/pyc_mode$ for f in *.py; do echo "###$f";
cat $f;done
###main.py
import test
test.test_func()
###test.py
#!/usr/bin/env python

def test_func() :
print "in_test_func"

if __name__ == '__main__':
test_func()
pengy@selenium:~/test/python/pyc_mode$ python main.py
in_test_func
pengy@selenium:~/test/python/pyc_mode$ ll
total 12
-rw------- 1 pengy lilab 29 2009-09-26 10:10:45 main.py
-rwx------ 1 pengy lilab 106 2009-09-26 10:19:17 test.py
-rwx------ 1 pengy lilab 339 2009-09-26 10:20:39 test.pyc
 
G

greg

Peng said:
-rw------- 1 pengy lilab 29 2009-09-26 10:10:45 main.py
-rwx------ 1 pengy lilab 106 2009-09-26 10:19:17 test.py
-rwx------ 1 pengy lilab 339 2009-09-26 10:20:39 test.pyc

Doesn't happen for me with 2.5 on Darwin.

What python/OS are you using?
 
G

greg

Also, what kind of file system are the files on?
Unixes often report the x bit as always being on
when the file system doesn't have x bits (e.g.
for FAT-based file systems).
 
G

greg

Peng said:
python 2.6.2 and CentOS

Just tried 2.6 on Darwin, and it does happen. So looks
like 2.6 has been changed to inherit the permission
bits from the .py. Makes sense, except that the x bits
should really be turned off.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top