Jump to content

Pywikipediabot/General basics/Invoking Python: Difference between revisions

From IdeaWazaWiki
wikademia>Millosh
wikademia>Eme
 
(2 intermediate revisions by one other user not shown)
(No difference)

Latest revision as of 17:07, 8 November 2009

Your bot should assume that it is multilingual. Because of that, use UTF-8 (or some better character set) and declare it at the beginning of your Python script:

<source lang="python">

  1. !/usr/bin/python
  2. -*- coding: utf-8 -*-

</source>

However, we will use Python interpreter for examples, invoked by simple typing "python". Interpreter doesn't require first two lines, but scripts written into a file have to have the first line and should have the second line.

If you are writing examples into the file and you want to execute it, you should choose one of two approaches:

  • You may give to your file executable mode (you need to do that only once!):

<source lang="bash"> $ chmod +x mybot.py </source>

... after which you would be able to execute your script directly:

<source lang="bash"> $ ./mybot.py </source>

  • Or you may invoke scripts by typing "python" before them:

<source lang="bash"> $ python mybot.py </source>