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 Introducing Dictionaries Introducing Dictionaries Update and Mutate Dictionaries

Son-Hai Nguyen
Son-Hai Nguyen
2,481 Points

How to copy the "course" into the interpreter?

How to How to copy the "course" into the interpreter, when you type "python3" into the Console?

Thanks guys

2 Answers

In the workspace, I'm not sure if there is a way to grab the text in the editor. The easiest way might be run python3, and then run "import dictionaries". This will load the program, and at that point you will have the courses variable set.

You may also be able to run "cat dictionaries.py", grab the text with your mouse, start python3, and then spit the text into the interpreter, however I'm not sure that works on all operating systems.

But in the end, there's nothing wrong with a little typing. :-)

Adrian's options work but to add to it, you can also type "python3 -i dictionaries.py" in the console which will run the dictionaries file and then allow you to interact with the file in the python console without having to explicitly import it. You can then access the course variable by referencing it by name instead of referencing the imported module first (e.g. dictionaries.course) as you would if you just typed "import dictionaries" directly into the python console. I tend to use "python3 -i ..." frequently and it works great for me so I figured I would add onto Adrian's answer.

Looks like cat dictionaries.py works best if you are just looking to get the contents of the file! :)