从备忘录里面找出来的:
Quine: Python & Brainfuck
```python
s='s=print s[:2]+chr(39)+s+chr(39)+chr(10)+s[2:]'
print s[:2]+chr(39)+s+chr(39)+chr(10)+s[2:]
```
So … the key is … 把那些在字符串中表达方式不一样的字符用其他方式代替(`”’”`, `”\n ”`)
另外…用`repr`(`%r`)算作弊吧……= =
```python
s='s={};print s.format(repr(s))';print s.format(repr(s))
```
更加 general 的方法:
```python
import sys
w = sys.stdout.write
s = [105,109,112,111,114,116,32,115,121,115,10,119,32,61,32,115,121,115,46,115,116,100,111,117,116,46,119,114,105,116,101,10,115,32,61,32,91,10,119,40,39,39,46,106,111,105,110,40,109,97,112,40,99,104,114,44,32,115,91,58,51,55,93,41,41,41,10,119,40,39,44,39,46,106,111,105,110,40,109,97,112,40,115,116,114,44,32,115,41,41,41,10,119,40,39,39,46,106,111,105,110,40,109,97,112,40,99,104,114,44,32,115,91,51,55,58,93,41,41,41,10
w(''.join(map(chr, s[:37])))
w(','.join(map(str, s)))
w(''.join(map(chr, s[37:])))
```
And … Brainf**k! (use `cat
quine.bf | sed 's/#.*//' | tr '\n' ' ' | sed 's/ //g ’`to remove comments and white spaces)
```
# Character map (according to frequency):
# + > < [ ] - .
# 1 2 3 4 5 6 7
# 43 62 60 91 93 45 46
# start
>>>
# data
>++
>++
>++
>++++
>+++
>+++++
>++
>++++
>++++
>+++
>+
>+++
>+
>++
>++
>++++++
>+++++
>+++
>++++
>++
>+
>+++
>++++++
>+++++
>++
>++++
>++
>+++++
>++
>++++
>++
>+++++
>+
>++++
>+++
>+++++
>+++
>++++
>+++
>+++++
>++
>++++++
>++++
>++++
>++
>+++++
>++
>++++
>++
>+++++
>+++
>+
>++++
>+++
>+++++
>+++
>++++
>+++
>+++++
>++
>++++++
>+++++
>++
>+++++
>+++
>+++
>++++++
>++
>++
>++
>++++
>++++
>++
>+++++
>++
>++++
>++
>+++++
>++
>+
>+
>+
>+
>+
>+
>+
>+
>++++
>+++
>+
>+
>+
>+
>+
>++
>++++++
>+++++
>+++
>+
>+
>+
>++++
>+++
>+++++
>+++
>++++
>+++
>+++++
>++
>++++++
>++++
>++++
>++
>+++++
>++
>++++
>++
>+++++
>+++
>++
>+
>+
>+
>+
>++++
>+++
>+
>+
>+
>+
>++
>++++++
>+++++
>+++
>+
>+
>+
>++++
>+++
>+++++
>+++
>++++
>+++
>+++++
>++
>++++++
>++++
>++++
>++
>+++++
>++
>++++
>++
>+++++
>+++
>++++++
>++++++
>++++
>+++
>+++++
>+++
>++++
>+++
>+++++
>++
>++++++
>++++
>++++
>++
>+++++
>++
>++++
>++
>+++++
>+++
>++
>+
>+
>+
>+
>+
>++++
>+++
>+
>+
>+
>+
>+
>+
>++
>++++++
>+++++
>+++
>+
>++++
>+++
>+++++
>+++
>++++
>+++
>+++++
>++
>++++++
>++++
>++++
>++
>+++++
>++
>++++
>++
>+++++
>+++
>+
>+
>++++
>+++
>+++++
>+++
>++++
>+++
>+++++
>++
>++++++
>++++
>++++
>++
>+++++
>++
>++++
>++
>+++++
>+++
>++
>+
>+
>+
>+
>+
>+
>+
>++++
>+++
>++++++
>++++++
>++++++
>++++++
>++++++
>++++++
>++++++
>++
>++++++
>+++++
>+++
>+
>++++
>+++
>+++++
>+++
>++++
>+++
>+++++
>++
>++++++
>++++
>++++
>++
>+++++
>++
>++++
>++
>+++++
>+++
>+
>++++
>+++
>+++++
>+++
>++++
>+++
>+++++
>++
>++++++
>+++++
>+++++
>+++++
>+++++
>+++++
>+++++
>++
>+++++
>+
>+
>+
>++++
>++
>++++
>+++
>+++
>+
>++
>++
>++++++
>+++++
>+++
>++++
>++
>+
>+++
>++++++
>+++++
>+++
>+++++++
>++
>++
>++++++
>+++++
>+++
>++++
>+++
>+++++
>++++++
>+++
>+
>++++
>+++
>+
>+++++
>+++
>++++
>+++
>+++++
>++
>++++
>+++
>+++
>+
>+
>+
>+
>+
>+
>+
>+
>++++
>++
>+
>+
>+
>+
>+
>+
>+
>+
>+++
>++++++
>+++++
>++
>++++++
>++++++
>+++++++
>+++
>+
>+
>+
>+
>++++
>++
>++++++
>++++++
>++++++
>++++++
>+++
>++++++
>+++++
>++
>++++++
>++++++
>++++++
>++
>++++
>+++
>+++++++
>++
>++++++
>+++++
>+++
>++++
>++++++
>+++++
>++
>++
>+++++
>+
>++++
>++
>+
>+++++
>++
>++
>++++
>+++++++
>++
>+++++
# return to first char
[<] >
# copy data
[ # for each data
[<+<+>>-] # copy to left two cells
<[>+<-]> # copy back from left cell
[>]>[>]+
[<]<[<]>-
[ # while greater than 0
[>]> [>]< +
[<]<[<]> -
]
>
]
<<->>
>
# Apply character map
[
# go to end of data plus 1; adds up to 43
[>]> [>]
>++++++++ # for range(8)
[<+++++>-] # adds 5
<+++ # adds 3
[<]<[<]> # return to the character
- # minus 1
# if greater than 0
[
# total 19
[>]> [>]<
>++++ # for range(4)
[<++++>-] # adds 4
<+++ # adds 3 (19 totally)
[<]<[<]>
-
[
[>]> [>]< -- # 62 to 60
[<]<[<]>
- # minus 1
[
[>]> [>]<
>+++++ # for range(5)
[<++++++>-] # adds 6
<+ # adds 1 (31 totally)
[<]<[<]>
-
[
[>]> [>]< ++ # adds 2
[<]<[<]> # go back to char
- # minus 1
# 93 to 45
[
[>]> [>]<
>+++++++ # for range(7)
[<------->-] # minus 7
<+ # adds 1 (minus 48 totally)
[<]<[<]>
-
[
[>]> [>]< + # adds 1
[<]<[<]> # go back to char
- # minus 1
]
]
]
]
]
]
> # go to next char
]
# Print first 3 ascii
+++
[
# move the data to left cell
> [<<+>>-] <
# move to right cell
[>+<-]
<.>> # print it
-
]
<[<]
# go to orig data
-<
+[<+]
<[<]>
# Print data (data format)
[
<<++++++++ # for range(8)
[>++++++++<-] # plus 8
>-- # 62
. # ">"
# 62 to 43
<++++ # for range(4)
[>----<-] # minus 4
>--- # 43
>
[<.>-] # print "+"
<[-]> # reset left cell to zero
>
]
+[>+] # go until 255
>>
[.>]
```
aka.
```
>>>>++>++>++>++++>+++>+++++>++>++++>++++>+++>+>+++>+>++>++>++++++>+++++>+++>++++>++>+>+++>++++++>+++++>++>++++>++>+++++>++>++++>++>+++++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>+++++>++>+++++>+++>+++>++++++>++>++>++>++++>++++>++>+++++>++>++++>++>+++++>++>+>+>+>+>+>+>+>+>++++>+++>+>+>+>+>+>++>++++++>+++++>+++>+>+>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>++>+>+>+>+>++++>+++>+>+>+>+>++>++++++>+++++>+++>+>+>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>++++++>++++++>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>++>+>+>+>+>+>++++>+++>+>+>+>+>+>+>++>++++++>+++++>+++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>+>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>++>+>+>+>+>+>+>+>++++>+++>++++++>++++++>++++++>++++++>++++++>++++++>++++++>++>++++++>+++++>+++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>+++++>+++++>+++++>+++++>+++++>+++++>++>+++++>+>+>+>++++>++>++++>+++>+++>+>++>++>++++++>+++++>+++>++++>++>+>+++>++++++>+++++>+++>+++++++>++>++>++++++>+++++>+++>++++>+++>+++++>++++++>+++>+>++++>+++>+>+++++>+++>++++>+++>+++++>++>++++>+++>+++>+>+>+>+>+>+>+>+>++++>++>+>+>+>+>+>+>+>+>+++>++++++>+++++>++>++++++>++++++>+++++++>+++>+>+>+>+>++++>++>++++++>++++++>++++++>++++++>+++>++++++>+++++>++>++++++>++++++>++++++>++>++++>+++>+++++++>++>++++++>+++++>+++>++++>++++++>+++++>++>++>+++++>+>++++>++>+>+++++>++>++>++++>+++++++>++>+++++[<]>[[<+<+>>-]<[>+<-]>[>]>[>]+[<]<[<]>-[[>]>[>]<+[<]<[<]>-]>]<<->>>[[>]>[>]>++++++++[<+++++>-]<+++[<]<[<]>-[[>]>[>]<>++++[<++++>-]<+++[<]<[<]>-[[>]>[>]<--[<]<[<]>-[[>]>[>]<>+++++[<++++++>-]<+[<]<[<]>-[[>]>[>]<++[<]<[<]>-[[>]>[>]<>+++++++[<------->-]<+[<]<[<]>-[[>]>[>]<+[<]<[<]>-]]]]]]>]+++[>[<<+>>-]<[>+<-]<.>>-]<[<]-<+[<+]<[<]>[<<++++++++[>++++++++<-]>--.<++++[>----<-]>--->[<.>-]<[-]>>]+[>+]>>[.>]
```