- Joined
- Aug 17, 2010
- Messages
- 247
- Reaction score
- 8
- Points
- 18
- Your Mac's Specs
- 2011 Mac mini and 2010 13" MacBook Pro, iPhone 4 and iPad
I picked up the O'Reilly Learning Python book the other day because I'm interested in learning how to write python code and now I'm stuck. I've written a file with a few basic statements the book provided and I can't figure out how to make Python find the file from system command line using Terminal. I've created the file in Text Wrangler and saved it with a .py extension and its in my documents folder under my user name. I can't seem to get the file to load or work. The statements in the file I created named script1.py are as follows
The statements I wrote run fine in the interactive python. Here is what I'm doing to open the file.
This is odd for me because that is what the book is saying to do but it's won't find the file. I understand the code and creating files and such, I have a problem using it to locate the directory or file on my Mac. I'm not sure if this is the same thing or not but it also mentions importing files as well. Here's what I did to try to import the file
The book mentions something about setting a PATH and I'm sure that is what I'm missing here. Can anyone help me out?
Code:
print(2*10)
x = 'Spam '!
print (x*8)
Code:
opened terminal - python script1.py
python: can't open file 'script1.py': [Errno 2] No such file or directory
Code:
opened terminal - python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import script1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named script1
>>>