error: an integer is required

MRAB python at mrabarnett.plus.com
Mon Jun 8 14:26:23 EDT 2009


madigreece at yahoo.gr wrote:
> I execute my code in linux environment.
> My code is:
> 
> from os import *
> 
> def insert_text_file(self, strng):
>      t=open("elements_file.txt", "a")
>      t.write(strng)
>      t.close()
> 
> I'm getting this error:
> 
> <type 'exception.TypeError'>: an integer is required
> 
> Where is the mistake?
> Help me, please!!

The os module has a function called 'open'. When you imported all of the
os module you hid the builtin 'open' with the one in the os module.

Wildcarded imports are generally not recommended for this reason.

Just use "import os" and then prefix with "os." wherever it's needed.



More information about the Python-list mailing list