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

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

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

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.

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

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?

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.