Member Avatar for HTMLperson5

This is a program intended to write text to any file specified

var_file = (raw_input('nof$ ') #nof, number of files.
try:
    text = str(raw_input('ttwtf$ ') #ttwtf, text to write to files.
    print text >>> var_file
except ValueError:
    print "Error: Not a string"
    main()

When the program starts the "try" part of the program it returns a syntax error. No details, just:
"SyntaxError: Invalid syntax"

Whats wrong?

You have unclosed opening parentheses on lines 1 and 3.

There are unbalanced parenthesis at lines 1 and 3 ...

SyntaxError usually means a very simple issue: most of the time an unbalanced parenthesis, sometimes a missing comma or colon ;)

Try this code:

var_file = (raw_input('nof$ ')) #nof, number of files.
try:
    text = str(raw_input('ttwtf$ ')) #ttwtf, text to write to files.
    print text >>> var_file
except ValueError:
    print "Error: Not a string"
    main()

text = str(raw_input('ttwtf$ ')

text = str(raw_input('ttwtf$ '))

is the correct method

What does using str on the result of raw_input accomplish? It's already a string.

Mild corrections to make this work:

var_file = raw_input('nof$ ') #nof, number of files.
try:
    text = raw_input('ttwtf$ ') #ttwtf, text to write to files.
    print text, ">>> ", var_file
except ValueError:
    print "Error: Not a string"
    #main()
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.