How to eliminate quotes around string field written to a file.

John Machin sjmachin at lexicon.net
Sat Nov 15 00:06:12 EST 2008


On Nov 15, 3:39 pm, len <lsumn... at gmail.com> wrote:
> hi
>
> Have this code in my program;
>
>     filename = 'custfile'
>     codeline = filename + ' = [\n'
>     output.write(codeline)
>
> record written to file look like this
>
>      "custfile" = [

Assuming output is a file object, what you say is not possible. Here's
a demonstration that your code above produces a file without quotes
around custfile.

=== start demo ===
C:\junk>type foo.txt
The system cannot find the file specified.

C:\junk>type len_demo.py
 output = open('foo.txt', 'w')
 filename = 'custfile'
 codeline = filename + ' = [\n'
 print 'repr(codeline) is', repr(codeline)
 output.write(codeline)

C:\junk>python len_demo.py
repr(codeline) is 'custfile = [\n'

C:\junk>type foo.txt
custfile = [

C:\junk>
=== end demo ===

I suggest that you remove the output file, and try your program again.
Check that you are not running some obsolete  version of your program.
If this code is in an imported module, remove any related .pyc
and .pyo files before you start.

HTH,
John



More information about the Python-list mailing list