Linux vim/vi下backspace(退格键)出现^? 或^H
当次删除操作,可以用【ctrl+w】以词为单位删除。一劳永逸的解决办法需按下面进行,二选一。vim/vi下退格键出现^? (bash下)
方式一:
编辑 .bash_profile 文件,添加一行 stty erase ^? 到最后。执行如下:
vi ~/.bash_profile
stty erase ^?
方式二:
vim/vi下退格键出现^H(csh下)
编辑 .cshrc 文件,添加一行 stty erase ^H 到最后。执行如下:
vi ~/.cshrc
stty erase ^H
p.s.:bash下 检查修改是否成功,输入命令:
stty -a
发现值 erase = ^?; 已经修改成功。
标签: vim vi bash stty backspace
python 如何通过subprocess.call调用自定义alias别名
为了更好的通过Python脚本执行linux命令,通过自定义别名(Alias)进行多个命令组合,然而通过python中如何通过subprocess类库
自定义alias
#alias lt='ls --human-readable --size -1 -S --classify'
alias lt='du -sh * | sort -h'
测试调用的Python代码
from subprocess import call
def test():
call("lt")
if __name__ == "__main__":
test()
直接运行上面的代码提示错误信息如下
Traceback (most recent call last):
File "test_alias.py", line 7, in <module>
test()
File "test_alias.py", line 4, in test
call("lt")
File "/Users/shiwei/anaconda3/lib/python3.7/subprocess.py", line 323, in call
with Popen(*popenargs, **kwargs) as p:
File "/Users/shiwei/anaconda3/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/Users/shiwei/anaconda3/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'lt': 'lt'
通过错误信息可以看出lt命令被当作了文件或目录提示找不到
如果您需要的别名是在 ~/.bashrc 中定义的,可以通过尝试以下几种方式进行运行:
1)你必须给’shell’关键字:
subprocess.call('command', shell=True)
否则,您给定的命令用于查找可执行文件,而不是传递给 shell,它是扩展别名和函数等内容的 shell。
from subprocess import call
def test():
call("lt", shell=True)
if __name__ == "__main__":
test()
运行此处代码发现报错找不到文件或目录的错误了,但是出现了新的错误,错误信息如下
# /bin/sh: lt: command not found
有错误信息可以看出还是找不到lt命令,不过不报错误了(此处应该有掌声)
2) 默认情况下,subprocess.call 使用’/bin/sh’ shell。如果这是您要调用的 Bash 别名,则需要使用“可执行”关键字 告诉子进程使用 bash 而不是 sh:
subprocess.call('command', shell=True, executable='/bin/bash')
代码如下
from subprocess import call
def test():
call("lt", shell=True, executable='/bin/bash')
if __name__ == "__main__":
test()
通过执行代码发现,报错的错误同上,还是提示lt找到
3) 但是,/bin/bash 除非作为“交互式”shell(使用“-i”)启动,否则不会获取 ~/.bashrc。不幸的是,您不能传递 executable=’/bin/bash -i’,因为它认为整个值是可执行文件的名称。因此,如果您的别名是在用户的正常交互式启动中定义的,例如在 .bashrc 中,您必须使用以下替代形式调用命令:
subprocess.call(['/bin/bash', '-i', '-c', 命令])
# i.e. shell=False (the default)
from subprocess import call
def test():
call(['/bin/bash', '-i', '-c', 'lt'])
if __name__ == "__main__":
test()
正常执行,成功调用了alias命令
标签: python subprocess alias
python2 python3中long类型的区别
python2 python3中long类型的区别
python2中有long类型
python3中没有long类型,只有int类型
go 语言的并发模型
Go语言的并发模型基于CSP(Communicating Sequential Processes)通信顺序进程模型,通过goroutine和channel来实现并发。Go语言的设计者希望并发成为一种简洁、高效、易于使用的机制,因此它的并发模型具备轻量、简单、安全等特点。以下是Go语言并发模型的几个核心概念:
1. Goroutine
Goroutine是Go语言的并发执行单元,类似于线程,但它比线程更轻量。Go的运行时调度器会负责管理成千上万的goroutine,而不会给系统带来沉重的负担。
特点:
轻量:Goroutine的启动成本非常低,初始栈大小只有几KB,而不是线程的几MB。并且,栈会根据需要动态增长。
高效调度:Go的调度器会自动把goroutine分布在不同的操作系统线程上执行,程序员无需手动管理。
简单启动:通过使用关键字go,可以轻松启动一个新的goroutine。例如:
go someFunction()
2. Channel
Channel是Go语言中用来在goroutine之间传递数据的通信机制。它是类型安全的,可以通过它将一个goroutine中的数据传递到另一个goroutine。
10 个 Linux 中方便的 Bash 别名
你有多少次在命令行上输入一个长命令,并希望有一种方法可以保存它以供日后使用?这就是 Bash 别名派上用场的地方。它们允许你将长而神秘的命令压缩为易于记忆和使用的东西。需要一些例子来帮助你入门吗?没问题!要使用你创建的 Bash 别名,你需要将其添加到 .bash_profile 中,该文件位于你的家目录中。请注意,此文件是隐藏的,并只能从命令行访问。编辑此文件的最简单方法是使用 Vi 或 Nano 之类的东西。
1、 你有几次遇到需要解压 .tar 文件但无法记住所需的确切参数?别名可以帮助你!只需将以下内容添加到 .bash_profile 中,然后使用 untar FileName 解压缩任何 .tar 文件。
alias untar='tar -zxvf '2、 想要下载的东西,但如果出现问题可以恢复吗?
alias wget='wget -c '
3、 是否需要为新的网络帐户生成随机的 20 个字符的密码?没问题。
alias getpass="openssl rand -base64 20"
'python' engine because the 'c' engine does not support regex separators
moveielens.py:17: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'.user = pd.read_table(path1, sep='::', header=None, names=unames)
pandas.read_table()函数,读取文件数据时,由于分隔符为'::',弹出如下警告
警告:ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex)
解决方法:增加函数的引擎参数engine='python',如下:
user = pd.read_table(path1, sep='::', header=None, names=unames, engine='python')
标签: python pandas re read_table
importError c extension: No module named np_datetine not buit
我的python代码中有import pandas
使用pyinstaller进行打包exe的时候出现以下问题,现在就来说一下。
打包的时候没有报错,
但是执行时候首先报了pandas的错。提示没有找到pandas._lilbs.tslibs.np_datetime。大概的错误如下:
第一个错误是:
Fi1e sitepackagesp\pandas\init .py 1ine 35 in Kmodule?
importError c extension: No module named np_datetine not buit. Jf you yant to import pandas from. the source drectory
g you may need to run python setup. py buildext inplace force to bui1d the c extensions first:
iFai1ed to execute script smg
通过网上查找的方法,修改下pyinstaller的用法,生成过程中添加--hiddenimport=pandas._libs.tslibs.np_datetime,代码如下
pyinstaller -F -w smg.py --hiddenimport=pandas._libs.tslibs.np_datetime
继续打包,过程中没有报错,继续执行exe文件的时候报错如下
第二个错误:
Fi1e sitepackagesp\pandas\init .py 1ine 35 in Kmodule?
Fi1e sitepackagesp\pandas\init .py 1ine 35 in Kmodule?
importError c extension: No module named timedeltas not buit. Jf you yant to import pandas from. the source drectory
g you may need to run python setup. py buildext inplace force to bui1d the c extensions first:
iFai1ed to execute script smg
iFai1ed to execute script smg标签: pandas np_datetime timedeltas
四个提高工作效率的小技巧
四个提高工作效率的小技巧:一)有没有那么一个命令,创建目录并切换至新目录下?
在工作中是不是经常使用mkdir创建目录,然后cd到创建的目录下,如果经常这样执行的话是不是特烦,抱怨为什么没有一个现成的命令供使用
纠结中。。。。。
如果这个时候有个方式可以满足你的需求是不是感觉很兴奋,然我们见证实现方式吧:
在当前登录的账号的~/.bash_profile文件中添加如下代码:
function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
然后执行 source ~/.bash_profile 使修改文件生效
这个时候你的服务器下就会有个新的命令,mkdircd
Example:
#mkdircd /tmp/a/b/c #pwd /tmp/a/b/c
RuntimeError: Python is not installed as a framework
今天在mac上,python virtualenv 虚拟环境下运行matplotlib example的时候提示如下报错:python animation/animated_histogram.py
Traceback (most recent call last):
File "animation/animated_histogram.py", line 11, in <module>
import matplotlib.pyplot as plt
File "/Users/shiwei/Documents/python_project/study_matplotlib/lib/python3.5/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/shiwei/Documents/python_project/study_matplotlib/lib/python3.5/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
[backend_name], 0)
File "/Users/shiwei/Documents/python_project/study_matplotlib/lib/python3.5/site-packages/matplotlib/backends/backend_macosx.py", line 17, in <module>
from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
标签: python matplotlib RuntimeError
valid phone numbers
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers.You may assume that a valid phone number must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit)
You may also assume each line in the text file must not contain leading or trailing white spaces.
Example:
Assume that file.txt has the following content:
987-123-4567
123 456 7890
(123) 456-7890
Your script should output the following valid phone numbers:
987-123-4567
(123) 456-7890
cat > file.txt <<EOF
987-123-4567
(123) 456-7890
0(001) 345-0000
(001) 123-345
热门日志
分类
- Django(4)
- ssdb(1)
- Mac(7)
- C(1)
- memcache(1)
- Python(32)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- about(1)
- git(9)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(2)
- 架构(19)
- Vue(1)
- game(2)
- Html(6)
- Java(8)
- Mysql(37)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(73)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Php(102)
- Windows(8)
- Message(48)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(12)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)
最新日志
- 成为架构师,如何真正具备“系统思维”?
- DHCP(Dynamic Host Configuration Protocol) 动态主机配置协议
- 从技术专家到战略领袖:成就技术总监的路径与思维
- python 如何读取超大的文件
- python requests 模块
- 如何给自己充电?
- 告别2024,迎接2025:深耕梦想,向前而行
- linux 的 dns 缓存,NSCD 服务
- The following untracked working tree files would be overwritten by checkout
- insecure connection not allowed,产生原因及如何解决