我正在使用一些CSV文件,使用以下代码:
reader = csv.reader(open(filepath, "rU"))
try:
for row in reader:
print 'Row read successfully!', row
except csv.Error, e:
sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
Run Code Online (Sandbox Code Playgroud)
一个文件抛出此错误:
file my.csv, line 1: line contains NULL byte
Run Code Online (Sandbox Code Playgroud)
我能做什么?谷歌似乎暗示它可能是一个Excel文件被不正当地保存为.csv.有什么方法可以解决Python中的这个问题吗?
==更新==
按照下面@ JohnMachin的评论,我尝试将这些行添加到我的脚本中:
print repr(open(filepath, 'rb').read(200)) # dump 1st 200 bytes of file
data = open(filepath, 'rb').read()
print data.find('\x00')
print data.count('\x00')
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出:
'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00\ .... <snip>
8
13834
Run Code Online (Sandbox Code Playgroud)
所以该文件确实包含NUL字节.
在SQL 2005中获得了一些基本XML作为XML数据类型.一个记录/行看起来像这样
<doc>
<level1>
<level2>
<name>James</name>
<age>12</age>
</level2>
<level2>
<name>John</name>
<age>23</age>
</level2>
</level1>
</doc>
Run Code Online (Sandbox Code Playgroud)
当我执行一些基本的T_SQL
SELECT TOP 1
DocumentXML.query('data(//doc/name)'),
DocumentXML.query('data(//doc/age)')
FROM [DBNAME].[dbo].[TBLNAME]
Run Code Online (Sandbox Code Playgroud)
我明白了
ID | Name | Age
----------------------
1 | JamesJohn | 1223
Run Code Online (Sandbox Code Playgroud)
如何重新编写T-SQL,使其显示为
ID | Name | Age
--------------------
1 | James | 12
2 | John | 23
Run Code Online (Sandbox Code Playgroud) 自从我从MVC 2升级到MVC 3 RC后,使用TryUpdateModel会导致NullReferenceException.仅当将我的操作方法作为单元测试的一部分运行时,才会出现此问题.在实际服务器上运行它按预期工作.
这是异常的堆栈跟踪:
System.NullReferenceException:未将对象引用设置为对象的实例.在System.Web.Mvc.JsonValueProviderFactory.GetValueProvider(ControllerContext controllerContext)的System.Web.Mvc.ValueProviderFactoryCollection.<> c_ DisplayClassc.b _7(ValueProviderFactory factory)处于System.Linq.Enumerable.WhereSelectEnumerableIterator
2.MoveNext() at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()处于System.1..ctor(IEnumerableSystem.Web.Mvc.Controller.TryUpdateModel中System.Web.Mvc.ValueProviderFactoryCollection.GetValueProvider(ControllerContext controllerContext)的System.Linq.Enumerable.ToList [TSource](IEnumerable`1 source)上的Collections.Generic.List 1 collection)[ TModel](TModel模型,字符串前缀)
......我自己的代码来自这里......
如果重要,我的控制器有以下签名:
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult Edit(int id, FormCollection collection)
{
}
Run Code Online (Sandbox Code Playgroud)
我的猜测是,这与DI在MVC3中工作的新方式有关,但我无法弄清楚我做错了什么.也许在MVC 3中需要一些DI设置,但在MVC 2中不需要?
asp.net-mvc dependency-injection model-binding asp.net-mvc-3
请告诉我,基本许可证中每个节点的最大记录是否有限制?例如,我每个基本许可证只能存储最多10M条记录?或者基本许可无限制记录数量?
谢谢!
我有一个WCF服务,它作为Windows服务托管.我们想在同一地址启用一个mex端点(但后缀为'/ mex').我一直在尝试使用以下配置执行此操作(失败):
<system.serviceModel>
<services>
<service
name="MyCompany.MyService"
behaviorConfiguration="defaultServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost"/>
</baseAddresses>
</host>
<endpoint
address="MyService"
binding="netTcpBinding"
contract="MyCompany.IMyService"
bindingConfiguration="netTcpBindingConfig"
/>
<endpoint
address="MyService/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="defaultServiceBehavior">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="netTcpBindingConfig" portSharingEnabled="true" />
</netTcpBinding>
</bindings>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
当它运行时,服务主机抛出一个AddressAlreadyInUseException抱怨"IP端点上已经有一个监听器0.0.0.0:808".这实际上对我有意义,因为端口共享服务已打开该端口,以便为MyService请求在此计算机上共享该端口的任何其他服务提供端点服务.
所以似乎mex端点想要对端口808进行exlusive访问.我可以通过调整mex端点来解决这个问题:
<endpoint
address="net.tcp://localhost:818/MyService/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"
/>
Run Code Online (Sandbox Code Playgroud)
这意味着mex端点现在拥有自己的专用端口.这方面的缺点是,任何其他想要公开mex端点的服务也需要一个唯一的端口用于其mex端点.这使得在查找mex端点时非常难以预测.
有没有办法强制mex端点参与端口共享?
计算第n个格雷码的公式为:
(n-1) XOR (floor((n-1)/2))
(Source: wikipedia)
Run Code Online (Sandbox Code Playgroud)
我把它编码为:
int gray(int n)
{
n--;
return n ^ (n >> 1);
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释上述公式是如何工作的,或者可能是它的推导?
我有一个带问题标记的自定义编辑器.标记在"问题"视图中正确显示图标,位置和文本,问题图标在编辑器的左边缘正确显示.
当我将鼠标悬停在边距中的问题标记图标上时,我想在弹出窗口中显示相同的错误消息文本,就像在Java编辑器中一样.现在没有弹出窗口.
有没有一种简单的方法来实现这一目标?
答案:
好吧,它看起来并不像标记系统中内置的功能.似乎已经提交了一个补丁,所以它可能会在以后的版本中添加,但在此之前它也很容易手工创建.
IAnnotationHover和实现的类getHoverInfo().getAnnotationHover()方法中返回类SourceViewerConfiguration.getHoverInfo()方法中,调用ISourceViewer.getAnnotationModel().getAnnotationIterator()以获取所有标记.你能告诉我如何在cookie中存储jsessionid,所以它可以通过post请求传递给servlet吗?我正在使用Apache HttpClient版本4.0.3.我发现的所有解决方案都解释了如何使用HttpClient 3.1执行此操作.我已经阅读了教程并试过这个,但它无法正常工作.
HttpPost httppost = new HttpPost(postData);
CookieStore cookieStore = new BasicCookieStore();
BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", getSessionId());
cookieStore.addCookie(cookie);
client.setCookieStore(cookieStore);
response = client.execute(httppost);
Run Code Online (Sandbox Code Playgroud)
编辑 - 进一步的解释
我正在连接到朋友写的servlet.我已登录并获得jsessionid.现在我想发送另一个请求,需要传递jsessionid用于授权目的.Servlet运行正常,因为我使用了Java HttpURLConnection,设置了cookie,传递了它并且它起作用了.现在使用HttpClient我没有异常但是来自friend的servlet的返回代码表明请求中没有sessionid.
另一个编辑 - 我有一个解决方案
我设置了请求标头的参数,它工作.Servlet识别的sessionid.
httppost.setHeader("Cookie", "JSESSIONID="+ getSessionId());
现在我的问题是:这种方法是否正确?
与动态SQL类似,其中String在运行时作为SQL执行,我们可以动态运行Java代码吗?就像我返回一个字符串,它是一个Java代码,然后我在运行时执行.这可能吗?