python在文本添加超链接_Python将超链接文本打印到Spyder控制台(Python print hyperlinked text to Spyder Console)...

Python将超链接文本打印到Spyder控制台(Python print hyperlinked text to Spyder Console)

我在Windows 7上使用WinPython发行版,它随Spyder IDE一起提供(我希望它在Anaconda上也能正常工作)。 我想知道如何将超链接文本打印到控制台输出。

我认为这是可能的,因为当我在我的代码中出现错误时,我得到了回溯,它显示了它崩溃的位置,并且这些链接是可点击的,然后将打开引发错误的函数行。 见下文:

(我不能在没有10个代表的情况下发布图片,这是蹩脚的,我是网站的新手)请看这里: http : //i.stack.imgur.com/oJ3Aw.png

但是,我不想只在IDE中打开一个文件,我想要做的是有一个指向文件夹位置的链接,我的代码只是将一些绘图图像保存到磁盘,当我点击链接时,有它在Windows资源管理器中打开该文件夹。 如果存在独立于平台的方式,那么奖励积分,但仅限Windows的解决方案对我来说就足够了。

我有一些以前存在的Matlab代码可以为我做这个,但我无法确定是否有Python等价物:

save_path = pwd;

fprintf('Plots saved to: %s\n',save_path,save_path);

I'm using the WinPython distribution on Windows 7, which comes with the Spyder IDE (and I hope this will work the same on Anaconda). I would like to know how to print hyperlinked text to the console output.

I assume it's possible, because when I get an error in my code, I get the traceback that shows me where it crashed, and those links are clickable, and will then open the line of the function where it raised the error. See below:

(I can't post the image without 10 rep, that's lame, I'm new to the site) See here: http://i.stack.imgur.com/oJ3Aw.png

However, I don't want to just open a file within the IDE, what I want to do is have a link to the folder location where my code just saved some plot images to disk, and when I click on the link, have it open the folder within windows explorer. Bonus points if there is a platform independent way of doing this, but a windows only solution would be sufficient for me.

I have some previously existing Matlab code that would do this for me, but I can't determine if there is a Python equivalent:

save_path = pwd;

fprintf('Plots saved to: %s\n',save_path,save_path);

原文:https://stackoverflow.com/questions/31975741

更新时间:2020-01-29 20:11

相关问答

你该走了 Run > Configuration per file (或者Ctrl+F6 ),然后在出现的对话框中查看 Command line options 并在那里写(例如) 1 2 3 关闭这个对话框并点击F5 ,你会看到你期待的输出。 注意 :请记住,这些命令行选项是作为文件运行配置的一部分保存在Spyder重启之间的,所以如果你想改变它们,你需要再次点击Ctrl+F6 。 You need to go Run > Configuration per file (or hit Ctrl+

...

( Spyder维护者在这里 )不,不幸的是没有办法再添加它。 我们决定删除它,因为Python控制台存在所有问题,正如您在上面提到的问题中提到的那样。 (Spyder maintainer here) No, unfortunately there's no way to add it back again. We decided to remove it because of all the problems the Python console had, as mentioned in th

...

非常有趣的问题! 幸运的是,IPython拥有适合您的魔力。 它被称为%logstart (请点击完整文档的链接)。 要开始使用它并保存所有命令的输入和输出,只需键入IPython控制台即可 In[1]: %logstart -o

并且会将您当时的会话记录到当前目录中名为ipython_log.py的文件中。 %logstart非常灵活,因此您可以选择要保存的其他文件,以及如何保存会话(纯Python或IPython命令)。 Very interesting question! Fortunat

...

( Spyder开发者在这里 )这是一个已知的问题,我们正在努力解决它。 不幸的是,我们仍在试图找出问题的根源。 注意 :这只发生在Windows上。 其他平台不受此问题的影响。 (Spyder developer here) This is a known problem and we're working to fix it. Unfortunately, we are still trying to find the source of the problem. Note: This onl

...

它已被弃用。 我在这里找到了一个参考: https : //github.com/pydata/pandas/pull/7499#issue-36016539 It has been deprecated. I find a reference here: https://github.com/pydata/pandas/pull/7499#issue-36016539

我正在运行不同版本的Spyder和Python,但能够重现你的问题。 确保您始终运行iPython控制台,这将确保您不会收到此错误。 这将有助于重新打开spyder。 I'm running a different version of Spyder & Python but was able to repro your issue. Make sure you always have an iPython console running, this will make sure you don'

...

( Spyder维护者在这里 )为了避免Spyder中的这个问题,我们一次只允许在控制台中显示500行( 注意 :此限制可由用户配置) 所以我会说Pycharm的控制台没有这个功能(虽然我无法确定)。 (Spyder maintainer here) To avoid this problem in Spyder we only allow 500 lines to be shown in the console at a time (Note: This limit is configurabl

...

( Spyder开发人员在这里 )您需要将qtconsole软件包更新到其版本4.3以修复此错误。 如果您使用的是Anaconda,则需要打开终端( cmd.exe )并运行此命令 conda update qtconsole

如果没有,你需要运行 pip install -U qtconsole

(Spyder developer here) You need to update the qtconsole package to its version 4.3 to fix this err

...

您可以在运行 - >配置(F6)中指定Spyder的运行设置。 默认情况下,选择“在当前Python或IPython控制台中执行”,您可能在Spyder中没有任何打开的控制台。 您可以选择“在新的专用Python控制台中执行”选项,Spyder将自动为您打开一个新控制台。 或者您可以离开dafault选项并在控制台菜单中自己创建一个新控制台。 You can specify the Spyder's Run Settings in Run -> Configure (F6). By default

...

好吧,通常要完成它,你必须重写python print内置函数。 但是......有ipython,它提供了一些钩子。 首先你需要安装ipython : #bash

sudo pip install ipython

(我使用sudo来简单找到我需要访问的文件夹,进一步阅读) 在ipython安装之后,您将拥有ipython扩展文件夹,所以请访问它: #bash

cd ~/.ipython/extensions/

并在那里创建一个名为print_to_file.py的文件,这里是它的内容: #p

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值