相关疑难解决方法(0)

带有额外空间的多行字符串(保留缩进)

我想使用以下内容将一些预定义的文本写入文件:

text="this is line one\n
this is line two\n
this is line three"

echo -e $text > filename
Run Code Online (Sandbox Code Playgroud)

我期待这样的事情:

this is line one
this is line two
this is line three
Run Code Online (Sandbox Code Playgroud)

但得到了这个:

this is line one
 this is line two
 this is line three
Run Code Online (Sandbox Code Playgroud)

我很肯定每个人都没有空间\n,但额外的空间是如何产生的?

string bash shell echo

353
推荐指数
8
解决办法
39万
查看次数

如何将多个语句放在一行中?

我不确定在什么标题下完全考虑这个问题,编码高尔夫看起来是合适的,如果有点不明确.

我对python有一点了解,但看起来很难"阅读".我看到它的方式,理解可能会完成与以下代码相同:

for i in range(10): if i == 9: print('i equals 9')
Run Code Online (Sandbox Code Playgroud)

这段代码比理解目前的工作方式更容易阅读,但我注意到你不能在一行中有两个':'......这也带给我了...

我的问题:

有什么方法可以让以下示例进入ONE LINE.

try:
    if sam[0] != 'harry':
        print('hello',  sam)
except:
    pass
Run Code Online (Sandbox Code Playgroud)

像这样的东西会很棒:

try: if sam[0] != 'harry': print('hellp',  sam)
except:pass
Run Code Online (Sandbox Code Playgroud)

但是我又遇到了相互冲突的':'我也很想知道是否有办法运行尝试(或类似的东西),除非,我需要放置除了之外似乎完全没有意义:传入那里.这是一条浪费的线.

谢谢你输入......这里有一个笑脸:D

python

129
推荐指数
6
解决办法
18万
查看次数

如何在终端中使用 python 编写多行代码?

如何在 python REPL 中编写多行代码?:

aircraftdeMacBook-Pro:~ ldl$ python
Python 2.7.10 (default, Jul 30 2016, 19:40:32) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
Run Code Online (Sandbox Code Playgroud)

例如示例:

i = 0

while i < 10:
    i += 1
    print i 
Run Code Online (Sandbox Code Playgroud)

在终端中,我不知道在 python shell 中热换行:

我测试了Control+ EnterShift+EnterCommand+ Enter,它们都错了:

>>> while i < 10:
... print i 
  File "<stdin>", line 2
    print i 
        ^
IndentationError: expected …
Run Code Online (Sandbox Code Playgroud)

python terminal

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

标签 统计

python ×2

bash ×1

echo ×1

shell ×1

string ×1

terminal ×1