FAQ
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.

Search Discussions

  • Brian Quinlan at Jul 21, 2004 at 1:31 pm

    Fred wrote:
    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
  • Fred at Jul 21, 2004 at 1:48 pm

    On Wed, 21 Jul 2004 15:31:00 +0200, Brian Quinlan wrote:
    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()
    Thank you Brian. That solved it :-)

    However, the above was just stuff I read on the web:

    http://diveintopython.org/file_handling/file_objects.html#d0e15055
    http://docs.python.org/tut/node9.html

    Thx again
    Fred.
  • Brian Quinlan at Jul 21, 2004 at 2:01 pm

    Fred wrote:
    Thank you Brian. That solved it :-)

    However, the above was just stuff I read on the web:

    http://diveintopython.org/file_handling/file_objects.html#d0e15055
    http://docs.python.org/tut/node9.html
    Here was your original code:

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

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

    Please let the list know if you have any other questions!

    Cheers,
    Brian
  • Fred at Jul 21, 2004 at 2:30 pm

    On Wed, 21 Jul 2004 16:01:04 +0200, Brian Quinlan wrote:
    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.
  • Brian Quinlan at Jul 21, 2004 at 2:37 pm

    Fred wrote:
    On Wed, 21 Jul 2004 16:01:04 +0200, Brian Quinlan wrote:

    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".
    Example 6.3. Opening a File
    f = open("/music/_singles/kairo.mp3", "rb")
    f
    <open file '/music/_singles/kairo.mp3', mode 'rb' at 010E3988>
    f.mode
    'rb'
    f.name
    '/music/_singles/kairo.mp3'

    Example 6.7. Writing to Files
    logfile = open('test.log', 'w')
    logfile.write('test succeeded')
    logfile.close()
    print file('test.log').read()
    test succeeded
    logfile = open('test.log', 'a')
    logfile.write('line 2')
    logfile.close()
    print file('test.log').read()
    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
  • Glenn Andreas at Jul 21, 2004 at 3:03 pm
    In article <mailman.663.1090420427.5135.python-list at python.org>,
    Brian Quinlan wrote:
    Fred wrote:
    On Wed, 21 Jul 2004 16:01:04 +0200, Brian Quinlan <brian at sweetapp.com>
    wrote:
    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".
    Example 6.3. Opening a File
    f = open("/music/_singles/kairo.mp3", "rb")
    f
    <open file '/music/_singles/kairo.mp3', mode 'rb' at 010E3988>
    f.mode
    'rb'
    f.name
    '/music/_singles/kairo.mp3'

    Example 6.7. Writing to Files
    logfile = open('test.log', 'w')
    logfile.write('test succeeded')
    logfile.close()
    print file('test.log').read()
    test succeeded
    logfile = open('test.log', 'a')
    logfile.write('line 2')
    logfile.close()
    print file('test.log').read()
    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?

    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
    f = PrivoxyWindowOpen("/music/_singles/kairo.mp3", "rb")
    f
    <open file '/music/_singles/kairo.mp3', mode 'rb' at 010E3988>
    f.mode
    'rb'
    f.name
    '/music/_singles/kairo.mp3'

    Example 6.7. Writing to Files

    logfile = PrivoxyWindowOpen('test.log', 'w')
    logfile.write('test succeeded')
    logfile.close()
    print file('test.log').read()
    test succeeded
    logfile = PrivoxyWindowOpen('test.log', 'a')
    logfile.write('line 2')
    logfile.close()
    print file('test.log').read()
    test succeededline 2
  • Fred at Jul 21, 2004 at 3:12 pm

    On Wed, 21 Jul 2004 10:03:06 -0500, Glenn Andreas wrote:
    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.
  • Brian Quinlan at Jul 21, 2004 at 3:12 pm

    Glenn Andreas wrote:
    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

    f = PrivoxyWindowOpen("/music/_singles/kairo.mp3", "rb")
    f
    Looks like it:
    http://www.privoxy.org/faq/trouble.html#WINDOWOPEN

    I think that this behavior (i.e. modifying the document content) is
    incredibly evil.

    Cheers,
    Brian
  • Nigel Rowe at Jul 21, 2004 at 3:26 pm

    Brian Quinlan wrote:

    Fred wrote:
    On Wed, 21 Jul 2004 16:01:04 +0200, Brian Quinlan <brian at sweetapp.com>
    wrote:
    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".
    <snip>
    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

    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.


    --
    Nigel Rowe
    A pox upon the spammers that make me write my address like..
    rho (snail) swiftdsl (stop) com (stop) au
  • Fred at Jul 21, 2004 at 4:35 pm

    On Thu, 22 Jul 2004 01:26:02 +1000, Nigel Rowe wrote:
    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.
  • Byron at Jul 21, 2004 at 3:49 pm
    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
    ------------------------



    Fred wrote:
    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.
  • Fred at Jul 21, 2004 at 4:43 pm

    On Wed, 21 Jul 2004 15:49:28 GMT, Byron wrote:
    Hope this helps,
    Sure does :-) Copy/paster for later use.

    Thank you
    Fred.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 21, '04 at 1:15p
activeJul 21, '04 at 4:43p
posts13
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase