22 Feb 2014, 17:07
Generic-user-small

JJ Burnam (2 posts)

I’m stuck. I created a file ‘temperature.py.’ Instructions say to save this file anywhere I like, so I saved it in a Dropbox subfolder: C:\Users\username\Dropbox\PythonCode

Book says:

Congratulations—you have created a module called ​temperature. Now that you’ve created this file, you can run it and import it like any other module:

>>>​ import temperature​​ >>>​ celsius = temperature.convert_to_celsius(33.3)​​ >>>​ temperature.above_freezing(celsius)​​ True

Here is what happens for me:

>>> import temperature Traceback (most recent call last): File “<pyshell#0>”, line 1, in import temperature ImportError: No module named 'temperature'

I don’t know where I have gone wrong. Any help appreciated

23 Feb 2014, 05:08
Generic-user-small

Jason Montojo (6 posts)

Hello,

The easiest way around this is to start your Python interpreter from the same folder as your module. Python will search this folder first for modules before it searches the usual system folders. For example, from the Windows command prompt, do this:

cd C:\Users\username\Dropbox\PythonCode
python

And then in the interpreter you should be able to import your module.

Hope this helps!

23 Feb 2014, 16:16
Generic-user-small

JJ Burnam (2 posts)

It did help, Jason. Thank you very much for the tip.

  You must be logged in to comment