syntax-error

Python cannot handle numbers string starting with 0. Why?

会有一股神秘感。 提交于 2019-11-26 12:29:50
I just executed the following program on my python interpreter: >>> def mylife(x): ... if x>0: ... print(x) ... else: ... print(-x) ... >>> mylife(01) File "<stdin>", line 1 mylife(01) ^ SyntaxError: invalid token >>> mylife(1) 1 >>> mylife(-1) 1 >>> mylife(0) 0 Now, I have seen this but as the link says, the 0 for octal does not work any more in python (i.e. does not work in python3). But does that not mean that the the behaviour for numbers starting with 0 should be interpreted properly? Either in base-2 or in normal base-10 representation? Since it is not so, why does python behave like

Notice: Trying to get property of non-object error

↘锁芯ラ 提交于 2019-11-26 12:25:52
i am trying to get data from: http://api.convoytrucking.net/api.php?api_key=public&show=player&player_name=Mick_Gibson but if i want to get player_name variable with this code: <? $js = file_get_contents('http://api.convoytrucking.net/api.php?api_key=public&show=player&player_name=Mick_Gibson'); $pjs = json_decode($js); var_dump($pjs->{'player_name'}); ?> i get error: Notice: Trying to get property of non-object in **\htdocs\index.php on line 9 + var_dump() returns: NULL var_dump($pjs) returns: array(1) { [0]=> object(stdClass)#52 (15) { ["player_name"]=> string(11) "Mick_Gibson" ["player_id"]

What is unexpected T_VARIABLE in PHP?

笑着哭i 提交于 2019-11-26 12:24:41
问题 I get this PHP error: Parse error: syntax error, unexpected T_VARIABLE From this line: $list[$i][$docinfo[\'attrs\'][\'@groupby\']] = $docinfo[\'attrs\'][\'@count\']; Is there anything wrong with this line? 回答1: There might be a semicolon or bracket missing a line before your pasted line. It seems fine to me, every string is allowed as array index. 回答2: It could be some other line as well, PHP is not always that exact. Probably you are just missing a semicolon on previous line. How to

Unexpected keyword_end error, yet syntax seems fine

若如初见. 提交于 2019-11-26 11:42:33
问题 This function is supposed to pull names from a Comma Separated Values file, and place them into an array. def xprt_csv_to_ary(csv_file) namecatcher_regex = \"/^[\\.{1}]([A-Z]+)\\.{3}/\" # Matches up to char before next name current_word = 0 names_array = [] while current_word < 5000 if current_word == 0 name = csv_file.readline.match(namecatched_regex) else name = csv_file.past_match.match(namecatcher_regex) end names_array[current_word] = name current_word ++ end return names_array end I\'m

Why can&#39;t attribute names be Python keywords?

江枫思渺然 提交于 2019-11-26 11:37:55
问题 There is a restriction on the syntax of attribute access, in Python (at least in the CPython 2.7.2 implementation): >>> class C(object): pass >>> o = C() >>> o.x = 123 # Works >>> o.if = 123 o.if = 123 ^ SyntaxError: invalid syntax My question is twofold: Is there a fundamental reason why using Python keyword attribute names (as in o.if = 123 ) is forbidden? Is/where is the above restriction on attribute names documented? It would make sense to do o.class = … , in one of my programs, and I am

How to solve SyntaxError on autogenerated manage.py?

拈花ヽ惹草 提交于 2019-11-26 11:15:38
问题 I\'m following the Django tutorial https://docs.djangoproject.com/es/1.10/intro/tutorial01/ I\'ve created a \"mysite\" dummy project (my very first one) and try to test it without altering it. django-admin startproject mysite cd mysite python manage.py runserver File \"manage.py\", line 14 ) from exc ^ SyntaxError: invalid syntax I\'m getting a SyntaxError on a file that was generated by the system itself. And I seem unable to find anyone else who has gone through the same issue. I\'ll add

Parse error: syntax error, unexpected &#39;[&#39;, expecting &#39;)&#39; [duplicate]

走远了吗. 提交于 2019-11-26 09:54:57
问题 This question already has answers here : PHP syntax for dereferencing function result (22 answers) Closed 6 years ago . I have this linecode $media = $dc->thumbnail->attributes()[\'url\']; runs fine on my local (WAMP) php 5.4.3 but when i host it on my server cpanel then it gives this error Parse error: syntax error, unexpected \'[\', expecting \')\' the php version on my server is 5.2.17 i dnt see any problem with it, please help 回答1: You need to be running PHP 5.4+ to use shorthand arrays

Parse error: syntax error, unexpected &#39;(&#39;, expecting &#39;,&#39; or &#39;;&#39; in

雨燕双飞 提交于 2019-11-26 09:53:04
问题 I am recieveing the following parse error: Parse error: syntax error, unexpected \'(\', expecting \',\' or \';\' in H:\\Programs\\USBWebserver v8.5\\8.5\\root\\oopforum\\func\\register.class.php on line 7 which relates to the following line of code in my class: private $random_name = rand(1000,9999).rand(1000,9999).rand(1000,9999).rand(1000,9999); I can not see why this line of code would cause a parse error? Here is some surrounding code: class register{ public $post_data = array(); private

Python print statement “Syntax Error: invalid syntax” [duplicate]

南楼画角 提交于 2019-11-26 09:38:45
问题 This question already has answers here : Syntax error on print with Python 3 [duplicate] (3 answers) Closed 5 years ago . Why is Python giving me a syntax error at the simple print statement on line 9? import hashlib, sys m = hashlib.md5() hash = \"\" hash_file = raw_input(\"What is the file name in which the hash resides? \") wordlist = raw_input(\"What is your wordlist? (Enter the file name) \") try: hashdocument = open(hash_file,\"r\") except IOError: print \"Invalid file.\" # Syntax error

Babel unexpected token import when running mocha tests

大城市里の小女人 提交于 2019-11-26 09:07:53
问题 The solutions offered in other related questions, such as including the proper presets (es2015) in .babelrc, are already implemented in my project. I have two projects (lets call them A and B) which both use ES6 module syntax. In Project A, I\'m importing Project B which is installed via npm and lives in the node_modules folder. When I run my test suite for Project A, I\'m getting the error: SyntaxError: Unexpected token import Which is preceded by this alleged erroneous line of code from