我似乎无法弄清楚如何为我的bash命令行提出正确的正则表达式.这就是我在做的事情:
echo "XML-Xerces-2.7.0-0.tar.gz" | sed -e's/^\(.*\)-[0-9].*/\1/g'
Run Code Online (Sandbox Code Playgroud)
这给了我......的输出
XML-Xerces-2.7.0
Run Code Online (Sandbox Code Playgroud)
...但我希望我需要输出...
XML-Xerces
Run Code Online (Sandbox Code Playgroud)
......我猜我能做到这一点......
echo "XML-Xerces-2.7.0-0.tar.gz" | sed -e's/^\(.*\)-[0-9].*/\1/g' | sed -e's/^\(.*\)-[0-9].*/\1/g'
Run Code Online (Sandbox Code Playgroud)
...但我想知道如何sed更好地理解正则表达式.
更新:
我试过这个......
echo "XML-Xerces-2.7.0-0.tar.gz" | sed -e's/^\([^-]*\)-[0-9].*/\1/g'
Run Code Online (Sandbox Code Playgroud)
......作为建议但是产出 XML-Xerces-2.7.0-0.tar.gz
我试图在Centos7服务器上编写一个python(版本2.7.5)CGI脚本.我的脚本试图从librivox的网页上下载数据...就像https://librivox.org/selections-from-battle-pieces-and-aspects-of-the-war-by-herman-melville/我的脚本一样,出现了这个错误:
<class 'urllib2.URLError'>: <urlopen error [Errno 13] Permission denied>
args = (error(13, 'Permission denied'),)
errno = None
filename = None
message = ''
reason = error(13, 'Permission denied')
strerror = None
Run Code Online (Sandbox Code Playgroud)
我已经关机iptables我可以做一些事情,比如`wget -O- https://librivox.org/selections-from-battle-pieces-and-aspects-of-the-war-by-herman-melville/ '没有错误.以下是发生错误的代码:
def output_html ( url, appname, doobb ):
print "url is %s<br>" % url
soup = BeautifulSoup(urllib2.urlopen( url ).read())
Run Code Online (Sandbox Code Playgroud)
更新:感谢Paul和alecxe我更新了我的代码:
def output_html ( url, appname, doobb ):
#hdr = {'User-Agent':'Mozilla/5.0'}
#print "url is %s<br>" % url
#req = url2lib2.Request(url, headers=hdr)
# soup …Run Code Online (Sandbox Code Playgroud) docker 可以写入 cd 吗?docker 可以执行吗
cdrecord dev=/dev/sr0 -checkdrive
Run Code Online (Sandbox Code Playgroud)
从 Ubuntu 容器?
Docker似乎可以使用父级的网络硬件,那为什么不能使用父级的cdrom/DVD设备呢?
更新:
这个问题是关于编程的,因为我有一些在我的 Ubuntu VM 上运行的 shell 脚本,我想知道迁移到 docker 是否可行。我很抱歉最初没有指出这一点:)
我正在尝试使用智能表.我按照这里提供的说明进行操作:http://lorenzofox3.github.io/smart-table-website/
因此,根据这些说明我需要做的就是运行,bower install angular-smart-table然后添加然后将模块添加angular.module('myApp',['smart-table']到角度应用程序中.这是我的角度应用:
# pwd
/var/www/html
# cat meanVoyApp.js
var app = angular.module("meanVoyApp", ['smart-table']);
Run Code Online (Sandbox Code Playgroud)
但是现在当我加载我的标记时,我在浏览器控制台中遇到了这些错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module meanVoyApp due to:
Error: [$injector:modulerr] Failed to instantiate module smart-table due to:
Error: [$injector:nomod] Module 'smart-table' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.14/$injector/nomod?p0=smart-table
Run Code Online (Sandbox Code Playgroud)
我没有拼错,所以我想我"忘了"加载它.那么如何加载呢?如何判断它是否已经加载而其他问题是什么?
谢谢!
我看起来能够并行迭代两个数组(或只有一个for循环).
这是我试过的剧本......
#!/usr/bin/env python
list1 = [ 'one', 'two', 'three' ]
list2 = [ 'I', 'II', 'III', 'IV', 'V' ]
for word in list1:
print word + " from list1"
for roman in list2:
print roman + " from list2"
for ( word, roman ) in (list1 list2):
if word:
print word + " from list1"
if roman:
print roman + " from list2"
Run Code Online (Sandbox Code Playgroud)
但是当我收到语法错误时显然是不正确的:
File "./twoarr.py", line 12
for ( word, roman ) in (list1 list2):
^
SyntaxError: invalid …Run Code Online (Sandbox Code Playgroud) 我对 git 分支行为感到困惑。
我有这个 git 仓库:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
Run Code Online (Sandbox Code Playgroud)
我创建了一个本地分支,如下所示:
$ git checkout -b foo
Switched to a new branch 'foo'
$ git branch
* foo
master
$ git status
On branch foo
nothing to commit, working tree clean
Run Code Online (Sandbox Code Playgroud)
现在我更改 README.md 文件。
$ date >> README.md
$ git status
On branch foo
Changes not staged for commit:
(use "git add <file>..." to update what will …Run Code Online (Sandbox Code Playgroud) 我正在开始使用 python,并且在使用 django 2.1 和 python 3.7 时遇到了许多其他人似乎也遇到过的问题。
以下是我到达这里的过程:
启动了虚拟环境
启动了 django 项目
尝试运行:
python 管理.py runserver
我一直收到错误:ModuleNotFoundError:没有名为“设置”的模块
我对以下问题进行了广泛的研究并找到了一些解决方案,但对我来说都不是有效的解决方案。有人遇到过这个问题吗?
任何见解都会有所帮助。提前致谢。
编辑:我的manage.py 文件如下所示:
#!/usr/bin/env python import os import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mytodoapp.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
Run Code Online (Sandbox Code Playgroud)
我的文件结构如下:
米托多应用程序
米托多应用程序
Run Code Online (Sandbox Code Playgroud)>__init__.py …
我知道如何做到这一点.我只是想从一个更大的字符串中获取一个子字符串并将其分配给标量.所以这是我破解的Perl脚本......
#!/usr/local/bin/perl
use warnings;
use strict;
my $thing = "thing1 thing2 thing3 thing4 thing5 thing6 thing7 thing8";
my $thing4 = ${@{split (/ /, $thing)}[3]};
print "thing4 is $thing4\n";
Run Code Online (Sandbox Code Playgroud)
...我得到的输出是......
Use of uninitialized value $_ in split at ./perlex.pl line 6.
Can't use string ("0") as an ARRAY ref while "strict refs" in use at ./perlex.pl line 6.
Run Code Online (Sandbox Code Playgroud)
......我希望输出结果......
thing4 is thing4
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
有没有办法引用yaml数组中的特定元素?例如,如果我有这点yaml:
node_list:
- one
- two
- three
Run Code Online (Sandbox Code Playgroud)
我可以做这样的事情:
first_node: node_list[0]
Run Code Online (Sandbox Code Playgroud) 我试图重写在Angular 2中可以正常工作的服务,并且试图重写Angular 6。
这是服务:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { environment } from '../../environments/environment';
import {Cluster} from "./cluster";
import {map} from "rxjs/internal/operators";
@Injectable({
providedIn: 'root'
})
export class FullDataService {
private headers = new Headers({'Content-Type': 'application/json'});
constructor(private http: HttpClient) {}
getClusters() {
const url = environment.apiUrl + '/api/v1/clusters';
return this.http.get(url).pipe(map(res => <Cluster[]>res));
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的app.models.ts:
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { NgModule …Run Code Online (Sandbox Code Playgroud) python ×3
angular ×1
angularjs ×1
bash ×1
django ×1
django-2.1 ×1
docker ×1
git ×1
javascript ×1
perl ×1
regex ×1
sed ×1
smart-table ×1
ubuntu ×1
yaml ×1