Def Syntax Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings
Syntax Error Definition
and policies of this site About Us Learn more about Stack Overflow python def main invalid syntax the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Def Syntaxerror Invalid Syntax
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it syntax error definition python only takes a minute: Sign up Error: Invalid Syntax on “def” up vote 0 down vote favorite So I'm getting Invalid Syntax where it says def before the add_entry function. I have no idea why. I tried commenting out, and then there was the same error on a different function. I'm using Python 2.7. date,number = 0,1 month,day,year = 1,2,0 from what is a syntax error in python datetime import datetime def home(): option = '' option = raw_input('Press ENTER to view log or input anything to add entries: ') print '\n' if option == '': view_log() else: add_entry() def view_log(): log_a = open('storage.txt', 'r') log_b = log_a.read() for line in log_b: print line[date[month]],line[date[day]],line[date[[year]],line[number] def add_entry(): old_entry = open('storage.txt', 'r') save = '' for line in old_entry: save = save + line new_entry = open('storage.txt','w') new = input_entry() save = save + str(new) + '\n' new_entry.write(save) def input_entry(): n_date = get_date() print 'Todays date is: %s/%s/%s' %(n_date[month],n_date[day],n_date[year]) n_number = raw_input('What was todays number? ') return (n_date,n_number) def get_date(): time_a = datetime.now() time_b = str(time_a) time_c = time_b.split(' ') time_d = time_c[0].split('-') time_e = tuple(time_d) return time_e python share|improve this question edited Jan 16 '14 at 16:06 Tshepang 4,6841059103 asked Jul 30 '11 at 17:23 user870876 1111 7 Pro tip: When you get a Syntax Error, always look at the preceding line, too. –Tim Pietzcker Jul 30 '11 at 17:31 add a comment| 1 Answer 1 active oldest votes up vote 5 down vote Your print
irregardless a word? Favorite Button CITE Translate Facebook Share Twitter Tweet Google+ Share
Invalid Syntax Python
syntax error noun in computing, an error in python syntaxerror invalid syntax a program due to a code that does not conform to order expected
Syntax Error Near Unexpected Token
by the programming language Examples A syntax error occurs when a user (or programmer) has put words in an order that http://stackoverflow.com/questions/6884764/error-invalid-syntax-on-def a program does not understand. Usage Note computing Dictionary.com's 21st Century LexiconCopyright © 2003-2014 Dictionary.com, LLC Cite This Source Discover our greatest slideshows 8 Offbeat Literary Genres to Get... Decode the pieces of our favorite... Know These 9 Commonly Confused... Uncover the http://www.dictionary.com/browse/syntax-error mysteries of the marks... Browse more topics on our blog What Is the Difference Between Discreet and Discrete? Learn the correct uses of these two commonly confused homophones. What Character Was Removed from the Alphabet? What mistaken pronunciation gave this character its name? Apostrophes 101 This small mark has two primary uses: to signify possession or omitted letters. How Do I Get a Word into the Dictionary? People invent new words all the time, but which ones actually make it? Word of the Day Word Value for syntax 16 16 Scrabble Words With Friends Nearby words for syntax error syntagma syntagmatic syntality syntax syntax directed translation syntax error syntax language syntax tree syntax-case syntax/semantic language syntaxes Pokémon Words About Terms & Privacy ©2016 Dictionary.com, LLC.
Get Kubuntu Get Xubuntu Get Lubuntu Get UbuntuStudio Get Mythbuntu Get Edubuntu Get Ubuntu-GNOME Get UbuntuKylin Ubuntu Code of Conduct Ubuntu Wiki Community https://ubuntuforums.org/showthread.php?t=1766911 Wiki Other Support Launchpad Answers Ubuntu IRC Support AskUbuntu Official Documentation User http://inventwithpython.com/blog/2012/07/09/16-common-python-runtime-errors/ Documentation Social Media Facebook Twitter Useful Links Distrowatch Bugs: Ubuntu PPAs: Ubuntu Web Upd8: Ubuntu OMG! Ubuntu Ubuntu Insights Planet Ubuntu Activity Page Please read before SSO login Advanced Search Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Python shows syntax error for syntax error 'def' Having an Issue With Posting ? Do you want to help us debug the posting issues ? < is the place to report it, thanks ! Page 1 of 2 12 Last Jump to page: Results 1 to 10 of 12 Thread: Python shows syntax error for 'def' Thread Tools Show Printable Version Subscribe to this Thread… Display Linear syntax error definition Mode Switch to Hybrid Mode Switch to Threaded Mode May 25th, 2011 #1 debd View Profile View Forum Posts Private Message Way Too Much Ubuntu Join Date Nov 2010 Beans 271 DistroUbuntu 10.10 Maverick Meerkat Python shows syntax error for 'def' Hi, I've been self-teaching python for some time. I wanted to modify and test a program example. the purpose is to create the final output look something like: *------------------* | Item1 36.00 | | Item2 39.00 | .................... | Total 75.00 | --------------------My problem is, when the compiler (2.7.1 , win32) encounters the second 'def' , it gives a 'syntax error'. What am I missing? the codes are below: Code: #to create the top and bottom formatting. #width is the line width, char is the string to be used #to draw the line def top_bottom(char,width): return '%s%s%s' % ('*', char*(width - 2), '*') #the function for formatting the line containing the item names and values def base_program(val1,left,val2,right): part2='%.2f' % val2 return '%s%s%s%s' % ('|', val1.ljust(left-2, ' '), part2.rjust(right-2,' '), '|') #data input s1=raw_input('Enter the first item
learning the language. Here's a list of common errors that result in runtime error messages which will crash your program. 1) Forgetting to put a : at the end of an if, elif, else, for, while, class, or def statement. (Causes “SyntaxError: invalid syntax”) This error happens with code like this: if spam == 42 print('Hello!') 2) Using = instead of ==. (Causes “SyntaxError: invalid syntax”) The = is the assignment operator while == is the "is equal to" comparison operator. This error happens with code like this: if spam = 42: print('Hello!') 3) Using the wrong amount of indentation. (Causes “IndentationError: unexpected indent” and “IndentationError: unindent does not match any outer indentation level” and “IndentationError: expected an indented block”) Remember that the indentation only increases after a statement ending with a : colon, and afterwards must return to the previous indentation. This error happens with code like this: print('Hello!') print('Howdy!') ...and this: if spam == 42: print('Hello!') print('Howdy!') ...and this: if spam == 42: print('Hello!') 4) Forgetting the len() call in a for loop statement. (Causes “TypeError: 'list' object cannot be interpreted as an integer”) Commonly you want to iterate over the indexes of items in a list or string, which requires calling the range() function. Just remember to pass the return value of len(someList), instead of passing just someList. This error happens with code like this: spam = ['cat', 'dog', 'mouse'] for i in range(spam): print(spam[i]) (Update: As a few have pointed out, what you might need is just for i in spam: rather than the above code. But the above is for the very legitimate case where you need the index in the body of the loop, rather than just the value itself.) 5) Trying to modify a string value. (Causes “TypeError: 'str' object does not support item assignment”) Strings are an immutable data type. This error happens with code like this: spam = 'I have a pet cat.' spam[13] = 'r' print(spam) What you probably want is this: spam = '