[newbie] Writing to file : "name 'concat' is not defined"?

F

Fred

Hi,

I've searched the web and the archives of this ng for half an
hour already, and I'm still stuck.

1. On a W2K Pro host, installed the latest ActivePython MSI. Rebooted.
2. Create test.py with the following:

file=concat('test.txt','w')
file.close()

3. Open a DOS box, and type either "test.py" or "python test.py":

"NameError: name 'concat' is not defined"

I tried the following:

- from operator import * -> "AttributeError: 'str' object has no
attribute 'close'"
- import operator -> "NameError: name 'concat' is not defined"
- file=concat('./test.txt','w')
- file=concat('.\test.txt','w')

.... all to no avail. Obviously, I'm either missing a package or I need
to tweak something. Any idea?

Thank you
Fred.
 
B

Brian Quinlan

Fred said:
Hi,

I've searched the web and the archives of this ng for half an
hour already, and I'm still stuck.

1. On a W2K Pro host, installed the latest ActivePython MSI. Rebooted.
2. Create test.py with the following:

file=concat('test.txt','w')
file.close()

Think about these two lines of code for a minute...what do you expect
"concat" to return? A file object? Maybe this would help:

file = open('test.txt', 'w')
file.close()

Or, even better (since "file" is a builtin object):

f = open('test'.txt', 'w')
f.close()

Cheers,
Brian
 
F

Fred

F

Fred

I don't see any reference to a "concat" function in either of those
resources.

Er...

Dive into Python : "Example 6.3. Opening a File" at the very
beginning. No mention of an "open" statement, just concat. Same lower
in "Example 6.7. Writing to Files".

And in the Python Tutorial, jump to "7.2 Reading and Writing Files"
The text mentions open(), but the samples don't show it, and use
concat() instead.

So I figured concat() was the way to go :)

Thx again
Fred.
 
B

Brian Quinlan

Fred said:
Er...

Dive into Python : "Example 6.3. Opening a File" at the very
beginning. No mention of an "open" statement, just concat. Same lower
in "Example 6.7. Writing to Files".

Example 6.3. Opening a File
'/music/_singles/kairo.mp3'

Example 6.7. Writing to Files
test succeededline 2
And in the Python Tutorial, jump to "7.2 Reading and Writing Files"
The text mentions open(), but the samples don't show it, and use
concat() instead.

Where is the usage of concat?

Cheers,
Brian
 
G

Glenn Andreas

Brian Quinlan said:
Example 6.3. Opening a File

'/music/_singles/kairo.mp3'

Example 6.7. Writing to Files

test succeededline 2


Where is the usage of concat?


Perhaps some sort of web-proxy is rewriting stuff?

If I look at the same thing (and I'm running Privoxy) I get:


Example 6.3. Opening a File
'/music/_singles/kairo.mp3'

Example 6.7. Writing to Files

test succeededline 2
 
F

Fred

Perhaps some sort of web-proxy is rewriting stuff?

If I look at the same thing (and I'm running Privoxy) I get:

Damn!!!!! I had no idea Privoxy would do this in pure HTML sections!
It had me fooled big time :-D

Sorry Brian for the inconvenience
Fred.
 
N

Nigel Rowe

Brian said:
Where is the usage of concat?

Cheers,
Brian


Ahhh, I've seen this before. I think the OP is browsing "Dive into Python",
by way of an old version of privoxy. By default its popup blocking
functions used to rewrite "window.open(..." as something like (from memory)
"concat(window, ....".

The newer verions rewrite it as "PrivoxyWindowOpen(..." which is at least a
bit more recognisable.
 
B

Byron

Hi Fred,

It looks like they have answered your questions. To reiterate in a
simple form, to open a file for reading, it is best to use something
like the following:

f = open("c:/test.txt", "r")
textlines = f.readlines() # Reads all lines into a list (array).
for line in textlines: # Prints each line that is read from the
text file.
print line

---

If you want to append (add additional information) to a text file, use
the following:

f = open("c:/test.txt", "a")
f.write("This is an appended line.\n")
f.close()


Hope this helps,

Byron
 
F

Fred

The newer verions rewrite it as "PrivoxyWindowOpen(..." which is at least a
bit more recognisable.

You guys are sharp :) For those bitten by the same "feature", make
sure you download the latest release of Privoxy
(privoxy_setup_3_0_3-2.exe as of this writing). Do NOT copy/paster
your config/filter files, as those that come with Privoxy have
changed. Instead, you'll have to copy/paster your personal filters
into the latest versions of those files as installed by Privoxy.

Then, instead of seeing open() replaced with concat(), you'll see:

f=PrivoxyWindowOpen('/tmp/workfile', 'w')

MMmm :)

Thx a bunch
Fred.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,291
Messages
2,571,493
Members
48,158
Latest member
CarmelaYou

Latest Threads

Top