0

Hello to everyone!
Yes, Im a newbie and I have a problem that is kind of a pain.
I receive an error "Invalid Syntax", when trying to run this.
The file mesaure.csv has been created and it is locate on the correct folder with the .py file. Whe I try tho run it I get the invalid syntax error on the last "row"
Im using Python 3.1.2 and IDLE or Eclipse.
Anyone can give a hand on this and tell me what it is that Im doing wrong??

Thanks

#!usr/bin/python
#Filename: mesaure.py


import csv
reader = csv.reader(open("mesaure.csv", "rb"))
for row in reader:
print row

6
Contributors
7
Replies
21
Views
7 Years
Discussion Span
Last Post by Gribouillis
0

Dont forget to select your code and press (CODE) next time.

And do you have a sample file, becasue this normally works.

import csv

for row in csv.reader(open('mesaure.csv')):
    print row

Edited by mike_2000_17: Fixed formatting

0

This should work, right?? ... I have tried a few things but still not working.
sorry about the code thing .. now I did :)

import csv
reader = csv.reader(open("mesaure.csv", "rb"))
for row in reader:
    print row
0

After running the file on a Terminal I get the results I want but is no working when running the same file, measured.py, on the editor. I have change the name from 'mesaure' to measured. This is what I get from the terminal:

carlos@ubuntu:~$ python measured.py

Why can't I run this same file that I run from the terminal on my editors??
That is the question.

0

Would it maybe easier to use my code snippet for text file based database (actualy card file would be more proper term)

0

Try it with the complete path name.

reader = csv.reader(open("/path/to/mesaure.csv", "rb"))

After running the file on a Terminal I get the results I want but is no working when running the same file, measured.py, on the editor.

This is too vague to comment on. What does "not working" mean?

Edited by woooee: n/a

0

Hello,
Anyone to help on this error?

File "./pyes2csv.py", line 54

        with open('esdata.csv', 'w', newline='') as csvfile:   
           ^
           SyntaxError: invalid syntax

My line of code:

    with open('esdata.csv', 'w', newline='') as csvfile:   
          filewriter = csv.writer( csvfile, delimiter='\t',  
                        quotechar='|', quoting=csv.QUOTE_MINIMAL)
        filewriter.writerow(["@timestamp", "session_event", "to_addr", "mno", "from_addr"])    

Thanks

0

@Temitope_2 you may be using an old version of python without a with statement. Run python --version to check.

Also don't revive old forum threads. Start your own thread instead if you have questions.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.