在ipython中运行粘贴代码的错误(Errors running pasted code in ipython)
我想从这里使用基本的
sklearn
iris
数据集代码:http://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.html
注意:为避免在第二行上出现编码问题,我将其从Ga {accent-e} l Varoquaux更改为Gael
print(__doc__) # Code source: Gael Varoquaux # Modified for documentation by Jaques Grobler # License: BSD 3 clause import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from sklearn import datasets from sklearn.decomposition import PCA # import some data to play with iris = datasets.load_iris() X = iris.data[:, :2] # we only take the first two features. Y = iris.target x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5 y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5 plt.figure(2, figsize=(8, 6)) plt.clf() # Plot the training points plt.scatter(X[:, 0], X[:, 1], c=Y, cmap=plt.cm.Paired) plt.xlabel('Sepal length') plt.ylabel('Sepal width') plt.xlim(x_min, x_max) plt.ylim(y_min, y_max) plt.xticks(()) plt.yticks(()) # To getter a better understanding of interaction of the dimensions # plot the first three PCA dimensions fig = plt.figure(1, figsize=(8, 6)) ax = Axes3D(fig, elev=-150, azim=110) X_reduced = PCA(n_components=3).fit_transform(iris.data) ax.scatter(X_reduced[:, 0], X_reduced[:, 1], X_reduced[:, 2], c=Y, cmap=plt.cm.Paired) ax.set_title("First three PCA directions") ax.set_xlabel("1st eigenvector") ax.w_xaxis.set_ticklabels([]) ax.set_ylabel("2nd eigenvector") ax.w_yaxis.set_ticklabels([]) ax.set_zlabel("3rd eigenvector") ax.w_zaxis.set_ticklabels([]) plt.show()
如果我在中间选择一个任意点将代码分成两部分并分别剪切并粘贴 - 那么代码工作正常。
但是,当粘贴整个片段时,后面的行会出现乱码:
In [267]: ax.set_title("First three PCA directions") Out[267]: <matplotlib.text.Text at 0x113726250> tor")68]: ax.seax.seax.seax.seax.seax.seax.se.wax.seax.seax.seax.seax.seax.seax.se.wal("2nd eigenvec --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-268-81e33d4e9263> in <module>() ----> 1 ax.seax.seax.seax.seax.seax.seax.se.wax.seax.seax.seax.seax.seax.seax.se.wal("2nd eigenvector") AttributeError: 'Axes3D' object has no attribute 'seax'
那么在这里有一个技巧能够将更多的文本粘贴到
ipython
吗? 请注意代码中没有选项卡 。 这是用于python 2.7.3
ipython 4.2.1
另外:我在OS / X上使用iterm2
:不确定这是否会起作用。根据(良好)建议进行更新 ,这也是通过
%cpaste
尝试的。 结果相同:将整个数量作为单个单位粘贴时,文本会被损坏。I am trying to use the basic
sklearn
iris
datasets code from here:http://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.html
NOTE: to avoid encoding issues on the 2nd line I changed to Gael from Ga{accent-e}l Varoquaux
print(__doc__) # Code source: Gael Varoquaux # Modified for documentation by Jaques Grobler # License: BSD 3 clause import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from sklearn import datasets from sklearn.decomposition import PCA # import some data to play with iris = datasets.load_iris() X = iris.data[:, :2] # we only take the first two features. Y = iris.target x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5 y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5 plt.figure(2, figsize=(8, 6)) plt.clf() # Plot the training points plt.scatter(X[:, 0], X[:, 1], c=Y, cmap=plt.cm.Paired) plt.xlabel('Sepal length') plt.ylabel('Sepal width') plt.xlim(x_min, x_max) plt.ylim(y_min, y_max) plt.xticks(()) plt.yticks(()) # To getter a better understanding of interaction of the dimensions # plot the first three PCA dimensions fig = plt.figure(1, figsize=(8, 6)) ax = Axes3D(fig, elev=-150, azim=110) X_reduced = PCA(n_components=3).fit_transform(iris.data) ax.scatter(X_reduced[:, 0], X_reduced[:, 1], X_reduced[:, 2], c=Y, cmap=plt.cm.Paired) ax.set_title("First three PCA directions") ax.set_xlabel("1st eigenvector") ax.w_xaxis.set_ticklabels([]) ax.set_ylabel("2nd eigenvector") ax.w_yaxis.set_ticklabels([]) ax.set_zlabel("3rd eigenvector") ax.w_zaxis.set_ticklabels([]) plt.show()
If I pick an arbitrary point in the middle to split the code into two pieces and cut and paste them separately - then the code works fine.
But instead when pasting the entire snippet at one time the latter lines get garbled:
In [267]: ax.set_title("First three PCA directions") Out[267]: <matplotlib.text.Text at 0x113726250> tor")68]: ax.seax.seax.seax.seax.seax.seax.se.wax.seax.seax.seax.seax.seax.seax.se.wal("2nd eigenvec --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-268-81e33d4e9263> in <module>() ----> 1 ax.seax.seax.seax.seax.seax.seax.se.wax.seax.seax.seax.seax.seax.seax.se.wal("2nd eigenvector") AttributeError: 'Axes3D' object has no attribute 'seax'
So is there a trick here to be able to paste larger amounts of text into
ipython
? Note there are no tabs in the code. This is foripython 4.2.1
withpython 2.7.3
Also: i'm usingiterm2
on OS/X: not sure whether that comes into play or not.Update based on a (good) suggestion this was also attempted via
%cpaste
. The results are the same: text gets corrupted when pasting the entire amount as a single unit.
原文:https://stackoverflow.com/questions/42461707
最满意答案
尝试更换
m = (Message)response.getItems().get(i);
同
m = service.getMessage(response.getItems().get(i).getItemId());
Try to replace
m = (Message)response.getItems().get(i);
with
m = service.getMessage(response.getItems().get(i).getItemId());
相关问答
更多-
您需要在代码中使用CalendarView,您可以在其中指定StartDate和EndDate。 例如对于那些追随我的人来说,这个问题最终与.NET或EWS库没有任何关系。 这个问题最终与我们公司负载均衡器上的持久性设置有关。 使用我们的负载平衡器,如果EWS流式订阅调用启用了任何类型的持久性,那么这些连接将失败。 不幸的是,当时我并不知道我和Exchange服务器之间有负载平衡器,因为开发人员无法在这里访问该基础架构。 无论如何,希望这有助于未来的人! For those who come after me, this issue wound up not being anything related t ...
如何检索消息和任务主体 - Exchange Web服务 - Java(How to retrieve Message and Task body - Exchange Web Services - Java)[2022-07-25]
尝试更换 m = (Message)response.getItems().get(i); 同 m = service.getMessage(response.getItems().get(i).getItemId()); Try to replace m = (Message)response.getItems().get(i); with m = service.getMessage(response.getItems().get(i).getItemId());使用Exchange Web服务跨Exchange搜索Exchange(Cross folder searching of Exchange using Exchange Web Services)[2022-07-12]
要在文件夹中查找项目,您可以创建搜索文件夹,并在SearchFolderParameters中将RootFolderIds设置为邮箱的根文件夹,将遍历模式设置为SearchFolderTraversal.Deep。 To find items across folders you can create a search folder and in the SearchFolderParameters set the RootFolderIds to the root folder of the mailbo ...在带有AQS的Exchange Web服务中按日期和时间搜索(Search by date and time in Exchange Web Services with AQS)[2023-04-26]
好的,我找到了解决方案。 只需添加一个Calendar变量,用DateFormat格式化并传递给查询字符串: protected static void searchByCategoryAndDateOldVersion() throws Exception{ ItemView view = new ItemView(Integer.MAX_VALUE); view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Asc ...来自消息的Independentsoft Exchange Web服务HTML为空(Independentsoft Exchange Web Services HTML from message is null)[2024-02-05]
FindItems不会返回您需要在有问题的项目上创建GetItem请求以获取这些属性的正文(以及许多其他属性),请参阅https://msdn.microsoft.com/en-us/library/bb508824。 ASPX FindItems doesn't return the body (and a number of other properties) you need to make a GetItem Request on the Item in question to get these ...无法建立与Exchange Web服务的连接 - Java API(Could not establish the connection to the Exchange Web Service - Java API)[2022-07-29]
问题是由于使用的认证方案。 默认情况下,EWS使用NTLM,但我的Exchange服务器未配置为接受这种类型的身份验证。 我必须使用LDAP认证。 The problem is due to the authentication scheme used. By default, EWS uses NTLM, but my Exchange server is not configured to accept this kind of authentication. I have to use LDAP au ...虚惊! 在Delphi应用程序中,我使用的是Developer Express调度程序组件,警告来自那里,而不是来自Outlook。 对不起;-) False alarm! In the Delphi application I was using a Developer Express scheduler component and the warning came from there, not from Outlook. Sorry ;-)您用于创建任务的任务类具有更新方法https://msdn.microsoft.com/EN-US/library/microsoft.exchange.webservices.data.task.update(v=exchg.80).aspx这是您用来更新任务的内容。 与EWS中的任何其他邮箱项目一样,在您可以更新它之前,您需要使用FindItems https://msdn.microsoft.com/en-us/library/office/dd633693(v=exchg.80).aspx来查找EW ...如果您指的是S / Mime加密,则必须根据RFC 3852和RFC 4134创建加密消息。 完成后,您可以发送消息。 使用EWS托管API,可以按如下方式完成: var item = new EmailMessage(service); item.MimeContent = new MimeContent(Encoding.ASCII.HeaderName, content); // Set recipient infos, etc. item.Send(); 编辑:您应该添加标准标题,如From,To ...相关文章
更多- reading notes for solr source code
- HDFS patch前后Ganglia看到running processes变化的分析
- English,The Da Vinci Code,Chapter 1-3
- Running Solr with Maven
- 微信会员注册开发【带源码】:网页授权,得到code后在当前页面获取openid,js+php实现跨域请求
- Another MySQL daemon already running with the same unix socket.
- Hadoop错误代码查询
- SSH中action到service的错误
- Hadoop 文件操作和代码运行测试
- 微信Android SDK示例代码及运行方法
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)