我想要这个结果。
---input---
"""
* name
- jon
* age
- 20
* hobby
- walk
"""
--- output ---
* name
- jon
* age
- 20
* hobby
- walk
----------------
我想在输入时打印
这是我写的代码。
val = ""
vals = []
while True:
val = input()
if val == 'q':
break
else:
我一直在做python的学习任务,我遇到了这个任务,我必须读取一个只包含很少单词的文件,如果一行是回文(向后写入时也是如此: lol > lol),所以我尝试使用此代码,但它不会在终端上打印任何内容:
with open("words.txt") as f:
for line in f:
if line == line[::-1]:
print line
但是如果我像这样打印,没有if条件,它会打印单词:
with open("words.txt") as f:
for line in f:
#include <stdio.h>
int main ()
{
FILE * fp;
int i,n;
char str[20];
printf("Enter the number of lines to be written: ");
scanf("%d", &n);
fp = fopen ("abc.txt","w");
for(i = 0; i < n+1;i++)
{
gets(str);
fputs(str, fp);
}
fclos
在Objective-C中使用UITextView收集用户输入时,如何限制用户一次尝试进行多个换行符?
所以,这就很好了:
This is my text.
Here is some more text.
但这并不是很好:
This is my text.
Here is some more text way down here.
Node.js中是否有一个函数可以从流中读取字符,直到它读取一个完整的JavaScript表达式并返回该表达式?read-eval-print循环中的"read“部分?
我希望从流中读取JSON对象,并在它们传入时对其进行处理。在这个用例中,我不需要REPL的交互部分。
{"r": 0.0,
"e": -0.2,
"t": 0.98}
// callback happens here with the content of the object
{"r": 0.2,
"e": 0.0,
"
所以我有一个从.Json创建CSV的程序。
首先,我加载json文件。
f = open('Data.json')
data = json.load(f)
f.close()
然后我浏览它,寻找一个特定的关键字,如果我找到那个关键字。我将在一个.csv文件中写入与此相关的所有内容。
for item in data:
if "light" in item:
write_light_csv('light.csv', item)
这是我的write_light_csv函数:
def write_light_csv(filenam
我从richtextbox中获取值,并希望将其保存在新的文本文档中
当我在富文本框中写入时,我希望将富文本框的文本保存在文本文档中,但它存储的方式类似于图像中所示。
我的密码
Using Sw As StreamWriter = File.CreateText(path)
Dim number As String = RichTextBox1.Text
Sw.WriteLine(number)
End Using
请帮帮忙
当用户输入多行输入时,我试图在多行中获得用户的输入,然后我将其存储在变量缓冲区中。为了打印相同的多行输入,我在每次迭代后添加\n。现在我想找到\n的索引。
import re
buffer = ''
while True:
line = raw_input()
if not line: break
buffer +='\n'
buffer += line
nlf="\\n"
nl=buffer.find(nlf)
print nl
我连接了两行,但我想要查找索引\n用户按enter?
我正在用C测试一个简单的程序:
int main() {
int c;
c = getchar();
while ( c != EOF ) {
printf("%c\n", c);
c = getchar();
}
}
然而,当我给出像'a','b‘这样的简单输入时,它会打印出“a\n,b\n”.谁能解释一下吗?谢谢!
☛ gcc hello.c; ./a.out
a
a
b
b
c
c