Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Python Data Types Splitting and Joining

I'm working in a launched workspace, and I forgot how to run a script saved as (string_split_Li. . ._py) in the console.

My line of thinking was that all I needed to do was to activate Python in the console and then call the file name (that I had already saved) at the shell>>> prompt, e.g.:

strings_List_Split_join.py ## that is a messy file/object name, haha

Here is copied code:

treehouse:~/workspace$ python
Python 3.5.0 (default, Feb 4 2016, 22:53:39)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.

strings_Lists_Split_join.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'strings_Lists_Split_join' is not defined

------------- I also tried to do some similar things like these below ----

import("strings_List_Split_join.py") load("strings_List_Split_join.py")

Thank you for you help!

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

To import the file as a module use:

>>> import strings_List_Split_join

Then refer to functions as strings_List_Split_join.function_name()

To run the code as if typed interactively use:

>>> from strings_List_Split_join import *