file=r'D:\tdx\vipdoc\szf10\300383.Txt'
text=open(file,"r").read()
Run Code Online (Sandbox Code Playgroud)
该文件可以读取,但起初我写道file:
file='D:\tdx\vipdoc\szf10\300383.Txt'
Run Code Online (Sandbox Code Playgroud)
我不能读它 text=open(file,"r").read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument: 'D:\tdx\x0bipdoc\\szf10\xc0383.Txt'
Run Code Online (Sandbox Code Playgroud)
在不使用的情况下我该怎么办file=r'D:\tdx\vipdoc\szf10\300383.Txt'?
也许我必须file用一些方法来逃避整个字符串?
问题是:文件是在开始时定义的,file现在是一个包含字符串的变量,我只能在程序中调用它,我该如何在程序中修复它.
file=r'D:\tdx\vipdoc\szf10\300383.Txt' 不能使用. file='D:\\tdx\\vipdoc\\szf10\\300383.Txt'也不能使用. 当程序已经运行时,给定file是一个字符串变量,我现在该如何修复它?
Say file不是字符串文字但是从代码的另一部分传递给我的代码,我无法修复使用正确的格式但仍希望能够使用文件名.
为什么我不能替换'D:\tdx\vipdoc\szf10\300383.Txt'为'D:\\tdx\\vipdoc\\szf10\\300383.Txt' simply withfile.replace("\","\\")`?
>>> file="D:\tdx\vipdoc\shf10\300383.Txt"
>>> file.replace("\x5c","\x5c\x5c") #can't work
'D:\tdx\x0bipdoc\\\\shf10\xc0383.Txt'
Run Code Online (Sandbox Code Playgroud)
我想把它分成两部分,失败了.
>>> filename = 'D:\tdx\vipdoc\szf10\300383.Txt'
>>> re.search('(.*?)(\d+\.Txt)',filename).group(1)
'D:\tdx\x0bipdoc\\szf10\xc0'
>>> re.search('(.*?)(\d+\.Txt)',filename).group(2)
'383.Txt'
Run Code Online (Sandbox Code Playgroud)
在Martijn Pieters的帮助下,我解决了它添加 '\300':r'\300'映射.
mapping = {'\a': r'\a', '\b': …Run Code Online (Sandbox Code Playgroud) 我想从向量中删除一个最大值和一个最小值.
> x<-c( 1,1,1,3,8,9,9)
Run Code Online (Sandbox Code Playgroud)
我希望得到1,1,3,8,9作为我的结果.
> y<-c(max(x),min(x))
> y
Run Code Online (Sandbox Code Playgroud)
[1] 9 1
setdiff(x,y)
[1] 3 8
setdiff无法工作.我怎么才能得到它?
我想编写自己的 sum 函数来获取可变长度参数的总和。
def myadd(*tuple):
sum=0
for element in tuple:
sum=sum+element
return(sum)
Run Code Online (Sandbox Code Playgroud)
调用方法一:
myadd(*(1,2,3,4))
Run Code Online (Sandbox Code Playgroud)
这是调用函数最正式的方式。这里没问题。
调用方法2:
myadd(1,2,3,4)
Run Code Online (Sandbox Code Playgroud)
它也可以得到结果,为什么?
调用方法3:
myadd((1,2,3,4))
Run Code Online (Sandbox Code Playgroud)
错误类型错误:+ 不支持的操作数类型:'int' 和 'tuple'。
在我看来,调用2和调用3不能被python接受,参数位置没有*运算符?你能告诉我python函数的操作原理吗?
我想在Python控制台中打印所有全角字符。
import re
for i in list(range(65281,65375)):
x=hex(i)
x='\\u'+re.search('.{4}$',x).group()
x.encode("latin1").decode("unicode-escape")
Run Code Online (Sandbox Code Playgroud)
我想使其更简单;重要的关键是要0xff01变为\\uff01,这是我进行转换的方法。
x='0xff01'
'\\u'+re.search('.{4}$',x).group()
Run Code Online (Sandbox Code Playgroud)
有没有更简单的方法可以做到这一点?
对于这里的代码结构
var mydo=sessionStorage.getItem("action");
function to_delete(){
var _table=document.getElementById("showTable");
//omit
}
window.onload=function(){
to_delete();
}
Run Code Online (Sandbox Code Playgroud)
我得到了理想的结果.现在重写代码结构如下:
var mydo=sessionStorage.getItem("action");
var _table=document.getElementById("showTable");
function to_delete(){
//omit
}
window.onload=function(){
to_delete();
}
Run Code Online (Sandbox Code Playgroud)
发生错误, TypeError: _table is null.
为什么不能设置document.getElementById为全局变量?
有一个表包含3列.现在我想设置第一列100px宽度,第二列200px和最后一列300px.
将所有td设置为具有哪个列的内容是一个尴尬.
有更明智的方法吗?
我想为10个变量分配相同的值,例如
v1 <- 1:10
v2 <- 1:10
....
v10 <- 1:10
eval(paste("v",1:10,"<-","1:10",sep="")) #can not get the result
Run Code Online (Sandbox Code Playgroud)
如何在R中以智能方式为多个变量分配相同的值?
A9在ascii表中代表©,如何A9在asthon中将ascii编码更改为utf-8编码?将asii编码改为utf-8的规则是什么?
为什么六个空白和五个空白会产生相同的效果?
<html>
hello<br/>hello<br/>
hello<br/>hello<br/>
</html>
Run Code Online (Sandbox Code Playgroud)
用firefox打开它.
2.还有问题
hello<br/>hello<br/>
Run Code Online (Sandbox Code Playgroud)
这里有五个空白,为什么网页上只显示三个空白?
环境:os 和 apache 以及 php 和 mariadb 版本。
uname -a
Linux MiWiFi-R3-srv 4.9.0-11-amd64 #1 SMP Debian 4.9.189-3+deb9u2 (2019-11-11) x86_64 GNU/Linux
sudo apachectl -v
Server version: Apache/2.4.25 (Debian)
Server built: 2019-10-13T15:43:54
php -v
PHP 7.0.33-0+deb9u6 (cli) (built: Oct 24 2019 18:50:20) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.33-0+deb9u6, Copyright (c) 1999-2017, by Zend Technologies
Run Code Online (Sandbox Code Playgroud)
使用密码登录 mariadb 并输入status:
Server: MariaDB
Server version: 10.1.41-MariaDB-0+deb9u1 Debian 9.9
Run Code Online (Sandbox Code Playgroud)
检查 …
我想创建一个数组,如 $animal = array("a" => "horse","b" => "fish").
在数组中一次创建一个元素(键和值)是约束条件,也就是说
在第一次创建键"a"和值"horse"时$animal = array("a" => "horse"),
在第二次创建时关键的"b"和价值"鱼",要做$animal = array("a" => "horse","b" => "fish").
我可以创建array("horse","fish")两次,第一次创建数组array("horse"),
第二次创建数组array("horse","fish").
<?php
$animal = array();
$x2 = "horse";
$x4 = "fish";
$animal[] = $x2;
$animal[] = $x4;
print_r($animal);
?>
Run Code Online (Sandbox Code Playgroud)
如何以相同的方式创建数组("a"=>"horse","b"=>"fish")?
<?php
$animal = array();
$x1 = "a";
$x2 = "horse";
$x3 = "b";
$x4 = "fish";
array_keys($animal[]) = $x1;
array_values($animal[]) = $x2;
array_keys($animal[]) = $x3;
array_values($animal[]) = …Run Code Online (Sandbox Code Playgroud)