Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Creating and Finding a Python file
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Lbatson21" data-source="post: 1273258" data-attributes="member: 169331"><p>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 [CODE]print(2*10)</p><p>x = 'Spam '!</p><p>print (x*8)[/CODE] The statements I wrote run fine in the interactive python. Here is what I'm doing to open the file. [CODE]opened terminal - python script1.py</p><p>python: can't open file 'script1.py': [Errno 2] No such file or directory[/CODE] 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 [CODE]opened terminal - python</p><p>Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) </p><p>[GCC 4.2.1 (Apple Inc. build 5646)] on darwin</p><p>Type "help", "copyright", "credits" or "license" for more information.</p><p>>>> import script1</p><p>Traceback (most recent call last):</p><p> File "<stdin>", line 1, in <module></p><p>ImportError: No module named script1</p><p>>>> </p><p>[/CODE]</p><p>The book mentions something about setting a PATH and I'm sure that is what I'm missing here. Can anyone help me out?</p></blockquote><p></p>
[QUOTE="Lbatson21, post: 1273258, member: 169331"] 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 [CODE]print(2*10) x = 'Spam '! print (x*8)[/CODE] The statements I wrote run fine in the interactive python. Here is what I'm doing to open the file. [CODE]opened terminal - python script1.py python: can't open file 'script1.py': [Errno 2] No such file or directory[/CODE] 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 [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 >>> [/CODE] The book mentions something about setting a PATH and I'm sure that is what I'm missing here. Can anyone help me out? [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Creating and Finding a Python file
Top