CVS file problem.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thesnake
    New Member
    • May 2010
    • 2

    #1

    CVS file problem.

    1. #! /usr/bin/env python
    2. import MySQLdb
    3. import re
    4. import csv
    5. db=MySQLdb.conn ect(host='local host', db='dbase', user='root',
    6. passwd='pass')
    7. c=db.cursor()
    8. c.execute('SELE CT text FROM tabelle WHERE page_title = "articles"
    9. result = c.fetchall()
    10. f = csv.writer(open ( "text1.txt" ,"w" ))
    11. for line in result:
    12. f.writerow(line )
    13. file= open("text1.txt ","rb")
    14. for line in file.readlines( ):
    15. p = re.compile(r'\[\[(.*?)\]\](.*?)[(\\\n\*\+)]')
    16. #p = line.replace("\ (\)" , " ")
    17. result = p.findall(line)
    18. f = csv.writer(open ("text2.txt" , "w").writerow(s tr(result))


    I do not have line 39 on my programm

    File "page_query_tes t.py", line 39

    ^
    SyntaxError: invalid syntax
  • woooee
    New Member
    • Mar 2008
    • 43

    #2
    Code:
    f = csv.writer(open("text2.txt" , "w").writerow(str(result))
    Check the number of left parens and right parens in this statement. I good IDE will assist with closing any punctuation you begin.

    Comment

    • thesnake
      New Member
      • May 2010
      • 2

      #3
      I see but i have now this error message
      Traceback (most recent call last):
      File "page_query_tes t.py", line 28, in <module>
      f = csv.writer(open ("wikiparsedexp .txt" , "w").writerow(s tr(result)))
      AttributeError: 'file' object has no attribute 'writerow'

      Comment

      • v0id
        New Member
        • May 2010
        • 3

        #4
        the error msg's pretty self-explanatory isn't it?

        f = csv.writer(open("wikiparsedexp. txt","w").writerow(str(result)))

        AttributeError: 'file' object has no attribute 'writerow'

        Comment

        Working...