小编ely*_*yon的帖子

如果条件表达不起作用

我有两个列表,其中包含以下值

List1=['6', '9', '16', '19', '0', '3', '6', '0', '6', '12', '18']

List2=['9', '16', '19', '24', '3', '6', '19', '6', '12', '18', '24']
Run Code Online (Sandbox Code Playgroud)

下面是我的python代码的循环,当idk为60时,if条件不起作用,时间= 60/60 = 1k

在这种情况下,当list1k为'0'且列表2为'3'时,它应该进入if条件.但是if条件不起作用.我也尝试使用以下表达式:

if ((time >=List1[i]) and (time <=List2[i])):
Run Code Online (Sandbox Code Playgroud)

这是代码:

for id in range(60,63):
    time = id/ 60
    for i in range(0, len(List1) - 1):
    if (((time >List1[i])or(time==List1[i])) and ((time <List2[i])or(time==List2[i]))):
        print "inside IF"
Run Code Online (Sandbox Code Playgroud)

python if-statement

2
推荐指数
1
解决办法
162
查看次数

在Python中将csv文件转换为管道分隔文件

我想使用Python将逗号分隔的CSV文件转换为管道分隔文件:

这就是我正在阅读我的csv文件的方式:

with open('C://Path//InputFile.csv') as fOpen:
    reader     =     csv.DictReader(fOpen)

    for row in reader:
        for (k, v) in row.items():
            columns[k].append(v)

c = csv.writer(open("C://Path//OutputFile.txt","wb"), delimiter="|")
Run Code Online (Sandbox Code Playgroud)

我如何将其写为管道分隔文件?

python csv

0
推荐指数
2
解决办法
1万
查看次数

标签 统计

python ×2

csv ×1

if-statement ×1