Active Topics

 


Reply
Thread Tools
Posts: 30 | Thanked: 42 times | Joined on Oct 2010 @ Russia
#11
1. Vi behaviour is rather strange, it shouldn't happen. You can use 'cat' instead.
Code:
cat >myscript.py # will overwrite myscript.py
# or
cat >>myscript.py # will append to the end
2. .py extension is not required. But you will get syntax highlighting in vim with it.

3. If you place script in MyDocs or other vfat partition, you will not be able to mark it as executable, since vfat does'n support unix permissions. Still, you can run a python script with
Code:
python scriptname.py
4. By errror messages ("import not found") it seems that script is executed with bash. Check that first line is #!/usr/bin/python and file has permissions 755, or just run it with 'python woof.py'.
 

The Following User Says Thank You to butler For This Useful Post:
thp's Avatar
Posts: 1,391 | Thanked: 4,272 times | Joined on Sep 2007 @ Vienna, Austria
#12
Originally Posted by hawaii View Post
Doesn't NEED .py as the top line of the script indicates the "interpreter" to use and the shell will pass it accordingly, upon execution.
It's called the shebang line, and it only comes into play when your script file is set executable (chmod +x), and you start it directly (i.e. "./myscript" or "myscript" if it's in your $PATH). If your script is in MyDocs (which is mounted noexec on Maemo 5), you cannot start it this way, so you always have to use the interpreter (which - in case of Python - lies in /usr/bin, and is executable) and pass the script as argument in that case.

You can also have Python scripts without the shebang line and without .py as extension - simply start it by passing it as argument to the Python interpreter ("python myscript"). The shebang line is also helpful for editors to autodetect the file type.
 

The Following User Says Thank You to thp For This Useful Post:
Posts: 2,225 | Thanked: 3,822 times | Joined on Jun 2010 @ Florida
#13
butler - wouldn't it be "echo", not "cat"?

At any rate, like I said (albeit perhaps in a confusing way), after I fixed the first line to say "#!/usr/bin/python" instead of "#!/usr/bin/env python" all the other errors went away.
 
Posts: 30 | Thanked: 42 times | Joined on Oct 2010 @ Russia
#14
Mentalist Traceur, "echo" prints it's command-line arguments to stdout, so "echo >script.py" will just create an empty file. If "cat" is executed without arguments, it copies stdin to stdout, so it will put into file everything you type on console. Ah, and afer paste you should type Ctrl-D, or "cat" will be listening for input forever.
 

The Following User Says Thank You to butler For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 08:28.