[Tutor] Sample9.py and Sample9.pyc & seting path to Python open files ...

David tayi177 at hotmail.com
Tue Nov 25 13:43:01 EST 2003


Hello ...


1.) I noticed, that after I have imported some random module (in this case, module I made) there appear an additional file in Python\Saves directory, where my modules are stored ...

The module I imported was Sample9.py (green icon), process it. and just after last line the new file Sample9.pyc appeared (more or less red icon) ...

It has also different content compare to "original" file, some sort of "program language" I do not recognize ...

Sample9.py

print "tadej"
multiplier = input("Which multiplier do you want? Pick a number ")
for j in range(1,13):
   print "%d x %d = %d" % (j, multiplier, j * multiplier)


Sample9.pyc

;ň
~ć˛?c           @   sE   d  GHe  d ƒ Z x- e d d ƒ D]
 Z d e e e e f GHq! Wd S(   s   tadejs,   Which multiplier do you want? Pick a number i   i
   s    %d x %d = %dN(   s   inputs
   multipliers   ranges   j(   s   js
   multiplier(    (    s/   D:\Program Files\Python\Lib\idlelib\Saves\gg.pys   ?   s     


What is that *.pyc file is  ??

What is it used for (just assuming something has changed in it during processing, compare to "original" .py file) ??




2.) Just before writting this mail, when I was trying to make some more complex "read/write" file operatons, I always get an error:

IOError [Errno 2] No such file or directory: 'Sample.py'

A also tryed with sys.path.append("D:\\PROGRAM~1\Python) function, which worked fine previous time, when Python didn't "know" the right path, and there was IOError again. Further, to be more certain I also tryed

 sys.path.append("D:\\PROGRAM~1\Lib\idlelib\Saves\) - the directory, where I store my sample files,  

... and there was the same error again. Please tell me, what am I doing wrong ??




3.) And only one question directly releated to programming:

I finished with Alan Gauld's tutorial (than you again, Alan - it's really the best option for non-programmer to start with), so to continue, I am learning from 4 new tutorials (not at the same time), one from techiwarehouse.com, second is Dive into Python, third is "An Informal Introduction to Python" from www.python.org and fourth is Josh Cogliati's "Python for Non-Programmers"

So in the one from techiwarehouse.com, there is an explanation of so-called Logical operators: and, or, and not. I do not understand explanation of and operator:

Firts it says:

For example, x > 0 and x < 10 is true only if x is greater than 0 and less than 10. 


and then:

Strictly speaking, the operands of the logical operators should be boolean expressions, but Python is not very strict. Any nonzero number is interpreted as "true."

>>> x = 5
>>> x and 1
1


>>> y = 0
>>> y and 1
0


So, how do we get 1 and 0 here ??
Probably they are not meaning "true" or "false", cause when I typed ...

>>> x = 1
>>> x and 2
2
... it gives value 2  !!


I assume it is releated to "Any nonzero number is interpreted as "true.", but I can't get it 100 % ...




Thanks for any answer, Tadey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20031125/57cb6f7f/attachment.html


More information about the Tutor mailing list