#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Just starting out


    Hey, I'm just starting out with Python and I'm seeing behavior that the book I'm using has completely skipped over.

    If I build a script with no imports, in Windows I can double click the .py file and it will execute. On the other hand, if I build a script with an import, on double click it doesn't execute but compiles into a subdirectory.

    Once this compile is done, I still can't execute the .py file, but have to execute the .pyc file instead.

    Is this normal?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    114
    Rep Power
    3
    I think you are misunderstanding what is going on.

    The .pyc file you see is simply a cached version of the imported module. The script that imports it should run exactly as it would otherwise. Executing the .pyc will execute whatever global code is in the imported module.

    If you don't want .pyc files to be created, run your script as "python -B yourscript.py" from a command line.

    Comments on this post

    • Dietrich agrees : agrees
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0
    Thanks for the reply ... it helped me realise that the issue was actually because my script had the same name as the module I was importing. Once I named it something different it runs as expected.

    Thanks again!

    Comments on this post

    • codergeek42 agrees : Thanks for replying with your solution. It'll help others who might run into a similar issue.

IMN logo majestic logo threadwatch logo seochat tools logo