为什么Pydev会为内置的python函数(如str())提供语法错误?
未定义的变量:str
未定义的变量:False
未定义的变量:float
我正在尝试创建并设置变量:
DECLARE myId INT;
SET myId = 5;
Run Code Online (Sandbox Code Playgroud)
但是,我在MySQL Workbench中收到无效的语法投诉:
'DECLARE myId INT'附近的SQL语法错误
我尝试了以下变种:
DECLARE myId INT(4);
SET myId = 5;
DECLARE @myId INT;
SET @myId = 5;
DECLARE @myId INT(4);
SET @myId = 5;
Run Code Online (Sandbox Code Playgroud)
怎么了?
致力于为学生创建语法调试练习。我们有以下例子。
def five():
print('five')
return 5
def hello();
print('hello')
Run Code Online (Sandbox Code Playgroud)
但是在运行文件时,语法错误是
def hello();
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
我已经看遍了,但无法弄清楚为什么编译器 [原文如此] 不抱怨函数外部的 return 关键字,而是首先找到它下面的分号错误。
Python以什么顺序检查文件语法?这是规范的一部分还是实现定义?
我正在尝试在javascript上构建一些东西,我可以输入一些像string,xml,javascript和(没有引号的非javascript字符串),如下所示:
//strings
eval("'hello I am a string'"); /* note the following proper quote marks */
//xml
eval(<p>Hello I am a XML doc</p>);
//javascript
eval("var hello = 2+2;");
Run Code Online (Sandbox Code Playgroud)
因此,前3个版本运行良好,因为它们是简单的javascript原生格式
但是当我尝试在javascript中使用它时
//plain-text without quotes
eval("hello I am a plain text without quotes");
//--SyntaxError: missing ; before statement:--//
Run Code Online (Sandbox Code Playgroud)
显然javascript将此解释为语法错误,因为它认为它的javascript抛出了一个SyntaxError.
所以我想做的是抓住这个错误并在发生这种情况时执行调整方法.
我已经尝试过try catch但它不起作用,因为它一旦尝试执行代码就会一直返回语法错误.
任何帮助将非常感激
干杯:)
附加信息:想象一下javascript将使用spidermonkey读取的外部文件,因此它是非浏览器的东西(我不能使用HttpRequest,DOM等...)..不确定这是否重要,但确实如此.:)
[root@234571-app2 git]# ./test.py
File "./test.py", line 4
with open("/home/git/post-receive-email.log",'a') as log_file:
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
代码如下所示:
[root@234571-app2 git]# more test.py
#!/usr/bin/python
from __future__ import with_statement
with open("/home/git/post-receive-email.log",'a') as log_file:
log_file.write("hello world")
Run Code Online (Sandbox Code Playgroud)
我正在使用Python 2.5.5
[root@234571-app2 git]# python -V
Python 2.5.5
Run Code Online (Sandbox Code Playgroud) 下面的函数使用"test-backup.ini"文件,解析它并通过update_option()方法将值输入到DB中.
但是,当ini文件的值包含特殊字符,如感叹号(!)和等号(=)(以及其他我猜的)时,它会在parse_ini_file($ file)中抛出PHP语法错误:
语法错误,意外"!"等...
例如,将此内容作为test-backup.ini文件...
[settings]
line1 = asc
line2 = /*.blog ul li {margin-bottom:0 !important;}*/
line3 = true
line4 = <meta name="google-site-verification" content="" />
Run Code Online (Sandbox Code Playgroud)
我在line2上遇到"!"的语法错误 并在第4行为"="
在将$文件传递给parse_ini_file()以处理这些字符时,我应该如何过滤$ file,以便在传递给update_option()时调用它们?
到目前为止,我发现的是:
字符{} |&〜![()"不得在键中的任何位置使用,并且在值中具有特殊含义.
$file = WP_PLUGIN_DIR.'/test/test-backup.ini';
if (file_exists($file) && is_readable($file))
{
$ini_array = parse_ini_file($file); //errors when value contains =, !, etc
foreach ($ini_array as $key=>$value) {
update_option($key, $value);
}
echo 'The settings have been saved';
}
else
{
echo 'alternate response here';
}
Run Code Online (Sandbox Code Playgroud)
?>
我在一个简单的测试应用程序上遇到以下错误,我正在努力学习Rails.
syntax error, unexpected '\n', expecting tCOLON2 or '[' or '.'
Run Code Online (Sandbox Code Playgroud)
它似乎告诉我有一个意外中断,但我无法弄清楚我的代码有什么问题:
#app/views/quotations/index.html.erb
<% title "Quotations" %>
<table>
<tr>
<th>Quote Text</th>
<th>Author</th>
<th>Quote type</th>
<th>Category</th>
<th>Tags</th>
</tr>
<% for @quotations.each do |quotation| %>
<tr>
<td><%= quotation.quote_text %></td>
<td><%= quotation.author %></td>
<td><%= quotation.quote_type %></td>
<td><%= quotation.category %></td>
<td><%= quotation.tags %></td>
<td><%= link_to "Show", [@user, quotation] %></td>
<td><%= link_to "Edit", edit_user_quotation_path(@user, quotation) %></td>
<td><%= link_to "Destroy", [@user, quotation], :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table> …Run Code Online (Sandbox Code Playgroud) 我有以下路线:
get 'users/:user_id/:name', to: 'profiles#show',
:constraints => { :name => /[a-zA-Z0-9_]+$/ }, as: 'user_profile'
Run Code Online (Sandbox Code Playgroud)
哪会产生错误:
Regexp anchor characters are not allowed in routing requirements: /[a-zA-Z0-9_]+$/
Run Code Online (Sandbox Code Playgroud)
所以我得到^字符是不允许的,但不确定是什么字符产生这个特定的路由错误.
Visual Studio看到的"语法错误"和"编译器错误"有什么区别?或者换句话说,为什么一些"编译时"错误用红色波浪线和一些蓝色波浪线加下划线?这是一个例子:

上面的红色下划线错误有以下描述:
方法'ValidateFilteredRecipient'没有重载需要6个参数
蓝色下划线错误有以下描述:
'ValidateBuild':不能在静态类中声明实例成员
我不清楚这两个错误的区别特征是什么.
我认为找到答案将是一块蛋糕:我只是谷歌它,第一个结果将是一个MSDN页面完全阐述这个主题; 然而,非常令人惊讶的是,事实并非如此.我开始试图谷歌的颜色(因为我还不知道红色意味着"语法错误",蓝色意味着"编译器错误"):
没有帮助.然后我尝试了这些搜索:
我可以看到这无处可去,所以我搜索了一下,找出了在VS中设置颜色的位置:工具>选项>环境>字体和颜色.顺便说一句,无法在这里搜索巨大的列表是非常烦人的,但我发现"语法错误"有红色波浪下划线,"编译器错误"有蓝色波浪下划线.

那是什么意思?回到Google:
没什么关系的.这是我从MSDN找到的最接近的:
此页面包含以下条目:
编译器错误 - 编辑器中的蓝色波形指示编译器错误.
和
语法错误 - 解析错误.
完全没有帮助 - 强调"完全".我一直以为我知道什么是"语法错误",至少,维基百科同意:
语法错误是用于以特定编程语言编写的字符序列或标记的语法中的错误.
此外,这是它的语法:
计算机语言的语法是一组规则,用于定义被认为是该语言中正确结构化的文档或片段的符号组合.
所以,从上面回到我的"语法错误":
方法'ValidateFilteredRecipient'没有重载需要6个参数
根据我在这里包含的定义,这是一个语法错误怎么样?实际上,在我看来,"编译器错误"我更加接近地满足了语法错误的定义:
'ValidateBuild':不能在静态类中声明实例成员
有人可以帮我解决这个问题吗?
我需要通过将其与vendorcitycode(由下划线分隔)连接来设置酒店代码,如下所示.
update schema.table_name set
hotelcode = hotelcode+"_"+vendorcitycode)
where vendorid = 'INV27' and vendorcitycode = 'LON'
Run Code Online (Sandbox Code Playgroud)
注意:
hotelcode并且vendorcitycode是两列类型character varying(100).我使用PostgreSQL 8.0.
syntax-error ×10
python ×3
.net ×1
c# ×1
declare ×1
eclipse ×1
ini ×1
javascript ×1
mysql ×1
parsing ×1
php ×1
postgresql ×1
pydev ×1
python-3.x ×1
quotes ×1
regex ×1
routes ×1
spidermonkey ×1
syntax ×1
try-catch ×1