我有一个要求用户输入的 shell 脚本。考虑下面的例子
测试文件
#!/bin/bash
echo -n "Enter name > "
read text
echo "You entered: $text"
echo -n "Enter age > "
read text
echo "You entered: $text"
echo -n "Enter location > "
read text
echo "You entered: $text"
Run Code Online (Sandbox Code Playgroud)
脚本执行:
sh test.sh
Enter name> abc
You entered: abc
Enter age > 35
You entered: 35
Enter location > prop
You entered: prop
Run Code Online (Sandbox Code Playgroud)
现在我在 python 程序中调用了这个脚本。我正在使用子流程模块执行此操作。据我所知,子流程模块创建了一个新流程。问题是当我执行 python 脚本时,我无法将参数传递给底层 shell 脚本,并且 scipt 处于 hault 阶段。能不能指出我做错的地方
python脚本(CHECK.PY):
import subprocess, shlex
cmd …Run Code Online (Sandbox Code Playgroud) 在下面的例子中,我想匹配字符串"Singapore",其中"S"应该始终为大写,其余单词可以是低位或大写.但是在下面的字符串中,"s"是小写的,并且在搜索条件中匹配.任何机构都可以让我知道如何实现这个?
import re
st = "Information in sinGapore "
if re.search("S""(?i)(ingapore)" , st):
print "matched"
Singapore => matched
sIngapore => notmatched
SinGapore => matched
SINGAPORE => matched
Run Code Online (Sandbox Code Playgroud) 在使用 Beautifulsoup 和 HTMl 解析器时,标签被转换为小写。但是我们如何在使用 LXML 解析器时实现。在下面的情况下,我无法打印输出。但是如果我使用 html 解析器进行解析。它工作正常。任何人都可以帮我吗?
html_doc = """
<html><HEAD><title>The Dormouse's story</title></HEAD>
<p class="title"><b>The Dormouse's story</b></p>
<p class="story">...</p>
"""
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc, "xml")
print soup.head
Run Code Online (Sandbox Code Playgroud)