where are the .pyc files?

S

Summercool

so i have always heard of the .pyc files.... but for some reason i
don't see them on the Windows platform... when i have a program
called try.py and after running it for ages, i still don't have a
try.pyc file in my folder even if i turn the "show hidden file" to on.
 
D

Dustan

so i have always heard of the .pyc files.... but for some reason i
don't see them on the Windows platform... when i have a program
called try.py and after running it for ages, i still don't have a
try.pyc file in my folder even if i turn the "show hidden file" to on.

Try "import try".

Ummm.... No, you can't.

Rename the file to "exodomuzos.py", then "import exodomuzos".
 
M

Marc 'BlackJack' Rintsch

so i have always heard of the .pyc files.... but for some reason i
don't see them on the Windows platform... when i have a program
called try.py and after running it for ages, i still don't have a
try.pyc file in my folder even if i turn the "show hidden file" to on.

The `*.pyc` files are usually only created when you import a module, not
when a module is run directly.

Ciao,
Marc 'BlackJack' Rintsch
 
S

Summercool

The `*.pyc` files are usually only created when you import a module, not
when a module is run directly.

how come a program that runs directly doesn't need to be optimized
into bytecode first? Or... is it that the interpreter will just run
the program as it goes by, without ever generating a .pyc file? So
what if you have a program that you only update every few weeks...
then you can ask a .pyc to be generated so that it runs faster every
time?
 
S

Steve Holden

Summercool said:
how come a program that runs directly doesn't need to be optimized
into bytecode first? Or... is it that the interpreter will just run
the program as it goes by, without ever generating a .pyc file? So
what if you have a program that you only update every few weeks...
then you can ask a .pyc to be generated so that it runs faster every
time?
You can, if you want, compile a program manually:

http://docs.python.org/lib/module-compileall.html

and run the resulting .pyc file if you wish. Most people don't bother,
though. If you have a very large main program you can encapsulate it as
a library and then call the library function from a teent-weeny main
program that isn't worth compiling.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline
 
S

Summercool

Summercool wrote:

You can, if you want, compile a program manually:

http://docs.python.org/lib/module-compileall.html

and run the resulting .pyc file if you wish. Most people don't bother,
though. If you have a very large main program you can encapsulate it as
a library and then call the library function from a teent-weeny main
program that isn't worth compiling.

that's great... I just wonder why there is no command line that says

python -c try.py

or something like that to force a generation of the byte code.
 
M

Marc 'BlackJack' Rintsch

how come a program that runs directly doesn't need to be optimized
into bytecode first?

Programs need to be compiled to bytecode and they actually are. The
bytecode is just not dumped into a file but compiled at every run.

Ciao,
Marc 'BlackJack' Rintsch
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top