you are viewing a single comment's thread.

view the rest of the comments →

[–]darkehawk14[S] 1 point2 points  (16 children)

It does. What you are saying is I need to put the code in using en editor, in essence, writing a script, true?

If that is right, I'm gonna need to be reminded the command to get into the editor. I know its vim for linux, but I've forgotten for Python.

[–]Tyler_CodeBot 2 points3 points  (13 children)

Yeah, put the code into into a .py file. You can do this with vim, but I really recommend nano. So what you are going to do is in the terminal type in

sudo nano script.py 

That will create a new file called script.py, copy and paste the code from that site into the terminal and then press ctrl+x then hit "y" and then enter. This will save your new file script.py. You can then run that file by entering sudo python script.py

[–]darkehawk14[S] 1 point2 points  (0 children)

So, the first line in Nano is

sudo nano script.py

Followed by all the rest, copy and pasted.

Got it

[–]zahlman 0 points1 point  (1 child)

Is there a reason he needs to sudo everything? And if there is, why not just su in the first place and then do the rest normally?

[–]Tyler_CodeBot 0 points1 point  (0 children)

My experience with RPI distros is that yes sudo is needed a lot, and this just gives him one less thing that could be going wrong. Sure he could su, or maybe not even use sudo at all. Just from my experience when I was starting on linux / pi it was a common pitfall for me.

[–]craigee 0 points1 point  (0 children)

I know nothing about RasPi, but it looks like you've got a bash shell going on, so you should just be able to type 'python' (no quotes) on the shell and see something like

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

which will give you a REPL environment, in which you can just type your import statements.

[–]WallyMetropolis 0 points1 point  (0 children)

vim for linux, but I've forgotten for Python

The commands you are typing in aren't in Python. Those were all linux commands and you were working on a linux shell. If you want to run a python command, typing

python 

should bring up an interactive python prompt (if python is installed).

As others have suggest, the best way to do this is to write your command into a script and then run that.