On Sat, Sep 26, 2009 at 8:10 AM, Steven D'Aprano
<st...@remove-this-cybersource.com.au> wrote:
> On Sat, 26 Sep 2009 06:57:52 -0500, Peng Yu wrote:
>
>> 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.
>
>
> [st...@sylar test]$ ls -l
> total 8
> -rw-rw-r-- 1 steve steve 6 2009-09-26 23:06 test.py
> [st...@sylar test]$ python2.6 test.py
> [st...@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:
>
> [st...@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.
>>>> import test
>>>> exit()
> [st...@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.

pe...@selenium:~/test/python/pyc_mode$ umask
0077
pe...@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
pe...@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()
pe...@selenium:~/test/python/pyc_mode$ python main.py
in_test_func
pe...@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
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to