我想找一个可以返回字符串一部分的linux命令.在大多数编程语言中,它都是substr()
功能.bash是否有任何可用于此目的的命令.我希望能够做这样的事情......
substr "abcdefg" 2 3
- 打印cde
.
随后的类似问题:
我正在创建一个需要进度条的小型控制台应用程序.就像是...
Conversion: 175/348 Seconds |========== | 50%
Run Code Online (Sandbox Code Playgroud)
我的问题是,你如何擦除已经打印到控制台的字符?当我达到第51个百分比时,我必须从控制台擦除这一行并插入一个新行.在我目前的解决方案中,这就是发生的事情......
Conversion: 175/348 Seconds |========== | 50%
Conversion: 179/348 Seconds |========== | 52%
Conversion: 183/348 Seconds |========== | 54%
Conversion: 187/348 Seconds |=========== | 56%
Run Code Online (Sandbox Code Playgroud)
我使用的代码是......
print "Conversion: $converted_seconds/$total_time Seconds $progress_bar $converted_percentage%\n";
Run Code Online (Sandbox Code Playgroud)
我在使用PHP的Linux中这样做(只有我会使用该应用程序 - 所以请原谅语言选择).因此,该解决方案应该适用于Linux平台 - 但如果您有一个跨平台的解决方案,那将更为可取.
我正在创建一个小应用程序必须能够接收URL.如果应用程序窗口打开,我应该能够从浏览器拖动链接并将其放入应用程序 - 应用程序将URL保存到数据库.
我在Python/GTk中创建它.但我对它的拖放功能有点困惑.那么,怎么做?
一些示例代码实现拖放(我的应用程序使用了一些此代码)...
import pygtk
pygtk.require('2.0')
import gtk
# function to print out the mime type of the drop item
def drop_cb(wid, context, x, y, time):
l.set_text('\n'.join([str(t) for t in context.targets]))
# What should I put here to get the URL of the link?
context.finish(True, False, time)
return True
# Create a GTK window and Label, and hook up
# drag n drop signal handlers to the window
w = gtk.Window()
w.set_size_request(200, 150)
w.drag_dest_set(0, [], 0)
w.connect('drag_drop', drop_cb) …
Run Code Online (Sandbox Code Playgroud) 我发现你无法使用Python的urllib2(或urllib)从一些网站上读取.一个例子...
urllib2.urlopen("http://www.dafont.com/").read()
# Returns ''
Run Code Online (Sandbox Code Playgroud)
当您使用浏览器访问该站点时,这些站点可以工作.我甚至可以使用PHP抓它们(没有尝试其他语言).我见过其他网站存在同样的问题 - 但目前还记不起网址.
我的问题是......