Jump to content

Pywikipediabot/General basics/Invoking Python

From IdeaWazaWiki
Revision as of 17:07, 8 November 2009 by wikademia>Eme (moved Archive:Pywikipediabot/General basics/Invoking Python to Pywikipediabot/General basics/Invoking Python over redirect)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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>