6 Replies - 1144 Views - Last Post: 07 October 2015 - 10:10 AM Rate Topic: -----

#1 albert003   User is offline

  • D.I.C Addict

Reputation: 39
  • View blog
  • Posts: 993
  • Joined: 15-December 14

Stuck on lesson #40 learn python the hard way

Posted 06 October 2015 - 02:05 PM

I'm at the beginning of the lesson and I can't figure out what I am doing wrong. I made a file and put a function in it called mystuff. I am using windows powershell.

# this goes in mystuff.py
def apple():
    print "I AM APPLES!"


I made a second file called apple.py and keyed in the following:
import mystuff
mystuff.apple()


When I try and run it I get the following error message.
File "exapple.py, line 1, in <module>
import mystuff
Import Error: No module named mystuff.

Is This A Good Question/Topic? 0
  • +

Replies To: Stuck on lesson #40 learn python the hard way

#2 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3215
  • View blog
  • Posts: 12,098
  • Joined: 03-December 12

Re: Stuck on lesson #40 learn python the hard way

Posted 06 October 2015 - 04:55 PM

Two questions then.

1. Is the import file actually named "mystuff.py"?
2. Are both files in the same location?
Was This Post Helpful? 0
  • +
  • -

#3 albert003   User is offline

  • D.I.C Addict

Reputation: 39
  • View blog
  • Posts: 993
  • Joined: 15-December 14

Re: Stuck on lesson #40 learn python the hard way

Posted 06 October 2015 - 07:33 PM

Yes the file is saved in mystuff.py and both are saved in the same location. The only reason I can think it cannot find it is because back in lesson #0 we were suppose to make a directory called mystuff.
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3215
  • View blog
  • Posts: 12,098
  • Joined: 03-December 12

Re: Stuck on lesson #40 learn python the hard way

Posted 06 October 2015 - 07:39 PM

Granted I am running this from IDLE, but the powershell shouldn't make the difference.

what is the directory structure?

Attached Image

Notice the file paths for these files and the output.
Was This Post Helpful? 0
  • +
  • -

#5 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3215
  • View blog
  • Posts: 12,098
  • Joined: 03-December 12

Re: Stuck on lesson #40 learn python the hard way

Posted 06 October 2015 - 07:51 PM

You said your second file was apple.py, but the error says, exapple.py


Are you running the right file?
Was This Post Helpful? 0
  • +
  • -

#6 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

Re: Stuck on lesson #40 learn python the hard way

Posted 07 October 2015 - 05:26 AM

Hmm... never thought to doing Python working in PowerShell. However, just for fun:
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.

PS baavgai> Set-Content mystuff.py

cmdlet Set-Content at command pipeline position 1
Supply values for the following parameters:
Value[0]: def apple():
Value[1]:     print("I AM APPLES!")
Value[2]:
PS baavgai> cat .\mystuff.py
def apple():
    print("I AM APPLES!")
PS baavgai> python
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:16:31) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import mystuff
>>> mystuff.apple()
I AM APPLES!
>>> ^Z

PS baavgai>



Seems to work.

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#7 albert003   User is offline

  • D.I.C Addict

Reputation: 39
  • View blog
  • Posts: 993
  • Joined: 15-December 14

Re: Stuck on lesson #40 learn python the hard way

Posted 07 October 2015 - 10:10 AM

View Postastonecipher, on 06 October 2015 - 07:39 PM, said:

Granted I am running this from IDLE, but the powershell shouldn't make the difference.

what is the directory structure?

Attachment pytest.PNG

Notice the file paths for these files and the output.



Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>

View Postastonecipher, on 06 October 2015 - 07:51 PM, said:

You said your second file was apple.py, but the error says, exapple.py


Are you running the right file?



I made the function and saved it in exmystuff.py.

I figured it out. I foolishly saved it in a file exmystuff.py when I should've just saved it in a file called mystuff.py.
It was my over sight. Thank you for your help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1