在终端或python中打印x个字符?(Printing x amounts of characters in terminal or python?)

编程入门 行业动态 更新时间:2024-10-28 18:25:46
终端或python中打印x个字符?(Printing x amounts of characters in terminal or python?)

如果我需要x个字符来测试我的程序,有没有办法用linux中的终端快速生成它们? 还是在python中? 例如,我想测试当我输入80个字符时我的程序是否中断。 但是,我希望能够在终端中生成80个字符,然后将其粘贴到我的程序(或管道等),而不是写80个字符。 我尝试过:

>>> for item in range (1,80): ... print "x",

它可以工作,但它打印x,中间有空格,超过80个字符

If i need x amount of characters to test my program, is there a way of generating them quickly with terminal in linux? or in python? for example I want to test if my program breaks when I enter 80 characters. But instead of writing 80 characters I want to be able to just generate 80 characters in terminal and then copy paste it to my program (or pipeline it etc). I tried doing:

>>> for item in range (1,80): ... print "x",

It works but it prints x with spaces inbetween which would be more than 80 characters

最满意答案

它必须是'x'吗? 对于随机字符串,您可以在shell中使用它

$ dd if=/dev/urandom count=80 bs=1

Does it have to be 'x's? For a random string you can use this from the shell

$ dd if=/dev/urandom count=80 bs=1

更多推荐

本文发布于:2023-07-22 14:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1220572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:终端   字符   python   Printing   characters

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!