我有一个CSV文件(usvd.csv),其中包含41列,我的bash脚本处理标题行以查看要打印的列,结果是我需要打印41列中的26列.这些可能不同 - CSV中的列数和/或需要打印的列数.
包含需要打印的列数的数组如下:
${UNIQUE[@]} = 1 2 3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 26 30 35 37 39 40 41
Run Code Online (Sandbox Code Playgroud)
因此,在41列中,我只想打印上面列出的列,它们可能因文件而异.
谢谢!!
我想输入一个命令行变量,然后将其相乘,但是当我打印变量时,它会重复我想要乘以的数字.
例如:
#!/usr/bin/env python3
import sys
st_run_time_1 = sys.argv[1]*60
print ("Station 1 : %s" % st_run_time_1)
Run Code Online (Sandbox Code Playgroud)
当我运行脚本时,我得到以下内容:python3 test.py 2
Station 1 : 222222222222222222222222222222222222222222222222222222222222
Run Code Online (Sandbox Code Playgroud) 我是 Python 新手,并且一直坚持打印由分隔符分隔的数组元素。我的数组由 60 000 奇数行组成,每行 26 个元素,其中一些元素仅包含数字,而其他元素则包含各种字符,包括特殊字符。例子:
a[0] = [abc,123,a1b2c3,*wewqe,...]
a[1] = [098i,qwerty,123qwe,xx-u,...]
Run Code Online (Sandbox Code Playgroud)
我希望输出是(最后一个元素后面没有“|”并且每一行都在自己的行上:
abc|123|a1b2c3|*wewqe,...
098i|qwerty|123qwe|xx-u,...
Run Code Online (Sandbox Code Playgroud)
我已尝试以下方法,但它们不起作用:
for row in results :
length = len(row)
print("")#throw in a new line
print ("Number of elements: " + str(length))
print '|'.join((str(row)))
Run Code Online (Sandbox Code Playgroud)
和这个:
for row in results :
length = len(row)
print("")#throw in a new line
print ("Number of elements: " + str(length))
for item in row:
print '|'.join(str(item))
Run Code Online (Sandbox Code Playgroud)
和这个:
for row in results :
length = len(row)
print("")#throw in a new …Run Code Online (Sandbox Code Playgroud)