Import text file

alex23 wuwei23 at gmail.com
Thu Jun 5 12:43:14 EDT 2008


On Jun 6, 2:28 am, Franck Y <franck... at gmail.com> wrote:
> I have a text file where there is
>
> xxx=value
> yyy=value
> zzz=value
> etc...
>
> I would like use the from myfile import xxxx
>
> Since it has not the extension py how can i read it ?
> I know the way to do it with the open file but i think this one is
> easier...

I don't think you'll be able to use import unless you change the file
extension to .py

If you're in control of the text file and are confident it will only
contain name=value pairs, try:

    execfile('your_file.txt')





More information about the Python-list mailing list