[Python-Dev] file open in python interpreter

adrian golding adriangolding at gmail.com
Tue Nov 4 09:16:38 CET 2008


hi all,

(benjamin and nick thank you!) i have another question to ask something
about permissions for the python interpreter.  in my earlier post, i was
saying i want to measure the python script before it is parsed.  what
happens is that i will write the measurement of that script file to another
file (call is 'measurereq') i have, it gives a Permission denied error.

i have modified other programs to do the same measurement (eg, modified Bash
to measure .sh files) and it works fine.  So i am suspecting it has
something to do with the python files. ie, i'm thinking the Permission
denied error is not because of i'm unable to write on my 'measurereq' file,
but its because i'm unable to measure (read) the python file.

any clues? how can i go around this?
thanks - adrian

On Mon, Nov 3, 2008 at 9:57 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> Benjamin Peterson wrote:
> > On Mon, Nov 3, 2008 at 7:25 AM, Benjamin Peterson
> > <musiccomposition at gmail.com> wrote:
> >> On Mon, Nov 3, 2008 at 1:04 AM, adrian golding <adriangolding at gmail.com>
> wrote:
> >>> hi all, i am trying to find out where is the part of the code in the
> python
> >>> interpreter that opens up the .py file and parses it. in particular, i
> am
> >>> trying to find the file open command in that file.  I greped and i just
> want
> >>> to make sure this is it: /Python-2.6/Parser/pgenmain.c
> >>> i am intending to take a hash measurement of the .py file just before i
> open
> >>> it to run the script.  is the above file the right place to call for
> the
> >>> measurement before the file open function?
> >> You want Parser/tokenizer.c.
> >
> > Sorry, that's not correct. opening of modules happens in
> > Python/import.c. There's also a case in Modules/main.c.
>
> And some indirect ones from runpy.py (via pkgutils) if you use the -m
> switch, or are executing a zipfile or directory.
>
> But for the specific case of an exact filename being provided on the
> command line, then main.c is the one the original poster will want to
> look at (line 567 to be exact).
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
> ---------------------------------------------------------------
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20081104/1d742944/attachment.htm>


More information about the Python-Dev mailing list