20230401在win10下复制粘贴python代码的问题【TAB惹的祸】

时间:2021-11-09 01:24:55

20230401在win10下复制粘贴python代码的问题【TAB惹的祸】
2023/4/1 16:07


习惯使用TAB按键而不是4个空格来分割代码块!
在WIN7下调通的python代码,生成一个使用ffmpeg来合并ts切片文件的脚本。
但是在WIN10下异常了!

temp = ""
url = "ffmpeg -i \"concat:"

#for n in range(1,10):
for n in range(1,999):
    #temp = "./1574/%03d.ts"%n
    temp = "%03d.ts|"%n
    url = url + temp
    #print(temp)
    #print(url)

temp = "%03d.ts"%(n+1)
url = url + temp

    
temp = "\" -c copy output1.ts"
url = url + temp

f=open("./1574/1.bat","w")
f.write(url)
f.close()


Microsoft Windows [版本 10.0.19045.2251]
(c) Microsoft Corporation。保留所有权利。

C:\Users\Sun>cd e:\1575

C:\Users\Sun>
C:\Users\Sun>e:

e:\1575>
e:\1575>python
Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> temp = ""
>>> url = "ffmpeg -i \"concat:"
>>>
>>> #for n in range(1,10):
>>> for n in range(1,999):
... #temp = "./1574/%03d.ts"%n
... temp = "%03d.ts|"%n
  File "<stdin>", line 3
    temp = "%03d.ts|"%n
    ^
IndentationError: expected an indented block after 'for' statement on line 1
>>> url = url + temp
>>> #print(temp)
>>> #print(url)
>>>
>>> temp = "%03d.ts"%(n+1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'n' is not defined
>>> url = url + temp
>>>
>>>
>>> temp = "\" -c copy output1.ts"
>>> url = url + temp
>>>
>>> f=open("./1574/1.bat","w")
>>> f.write(url)
38
>>> f.close()
>>>
>>>

20230401在win10下复制粘贴python代码的问题【TAB惹的祸】
将TAB按键使用4个空格替代即可:

 


temp = ""
url = "ffmpeg -i \"concat:"

#for n in range(1,10):
for n in range(1,999):
    #temp = "./1574/%03d.ts"%n
    temp = "%03d.ts|"%n
    url = url + temp
    #print(temp)
    #print(url)

temp = "%03d.ts"%(n+1)
url = url + temp

    
temp = "\" -c copy output1.ts"
url = url + temp

f=open("./1574/1.bat","w")
f.write(url)
f.close()


ffmpeg -i "concat:001.ts|002.ts|003.ts|004.ts|005.ts|006.ts|007.ts|008.ts|009.ts|010.ts|011.ts|012.ts|013.ts|014.ts|015.ts|016.ts|017.ts|018.ts|019.ts|020.ts|021.ts|022.ts|023.ts|024.ts|025.ts|026.ts|027.ts|028.ts|029.ts|030.ts|031.ts|032.ts|033.ts|034.ts|035.ts|036.ts|037.ts|038.ts|039.ts|040.ts|041.ts|042.ts|043.ts|044.ts|045.ts|046.ts|047.ts|048.ts|049.ts|050.ts|051.ts|052.ts|053.ts|054.ts|055.ts|056.ts|057.ts|058.ts|059.ts|060.ts|061.ts|062.ts|063.ts|064.ts|065.ts|066.ts|067.ts|068.ts|069.ts|070.ts|071.ts|072.ts|073.ts|074.ts|075.ts|076.ts|077.ts|078.ts|079.ts|080.ts|081.ts|082.ts|083.ts|084.ts|085.ts|086.ts|087.ts|088.ts|089.ts|090.ts|091.ts|092.ts|093.ts|094.ts|095.ts|096.ts|097.ts|098.ts|099.ts|100.ts|101.ts|102.ts|103.ts|104.ts|105.ts|106.ts|107.ts|108.ts|109.ts|110.ts|111.ts|112.ts|113.ts|114.ts|115.ts|116.ts|117.ts|118.ts|119.ts|120.ts|121.ts|122.ts|123.ts|124.ts|125.ts|126.ts|127.ts|128.ts|129.ts|130.ts|131.ts|132.ts|133.ts|134.ts|135.ts|136.ts|137.ts|138.ts|139.ts|140.ts|141.ts|142.ts|143.ts|144.ts|145.ts|146.ts|147.ts|148.ts|149.ts|150.ts|151.ts|152.ts|153.ts|154.ts|155.ts|156.ts|157.ts|158.ts|159.ts|160.ts|161.ts|162.ts|163.ts|164.ts|165.ts|166.ts|167.ts|168.ts|169.ts|170.ts|171.ts|172.ts|173.ts|174.ts|175.ts|176.ts|177.ts|178.ts|179.ts|180.ts|181.ts|182.ts|183.ts|184.ts|185.ts|186.ts|187.ts|188.ts|189.ts|190.ts|191.ts|192.ts|193.ts|194.ts|195.ts|196.ts|197.ts|198.ts|199.ts|200.ts|201.ts|202.ts|203.ts|204.ts|205.ts|206.ts|207.ts|208.ts|209.ts|210.ts|211.ts|212.ts|213.ts|214.ts|215.ts|216.ts|217.ts|218.ts|219.ts|220.ts|221.ts|222.ts|223.ts|224.ts|225.ts|226.ts|227.ts|228.ts|229.ts|230.ts|231.ts|232.ts|233.ts|234.ts|235.ts|236.ts|237.ts|238.ts|239.ts|240.ts|241.ts|242.ts|243.ts|244.ts|245.ts|246.ts|247.ts|248.ts|249.ts|250.ts|251.ts|252.ts|253.ts|254.ts|255.ts|256.ts|257.ts|258.ts|259.ts|260.ts|261.ts|262.ts|263.ts|264.ts|265.ts|266.ts|267.ts|268.ts|269.ts|270.ts|271.ts|272.ts|273.ts|274.ts|275.ts|276.ts|277.ts|278.ts|279.ts|280.ts|281.ts|282.ts|283.ts|284.ts|285.ts|286.ts|287.ts|288.ts|289.ts|290.ts|291.ts|292.ts|293.ts|294.ts|295.ts|296.ts|297.ts|298.ts|299.ts|300.ts|301.ts|302.ts|303.ts|304.ts|305.ts|306.ts|307.ts|308.ts|309.ts|310.ts|311.ts|312.ts|313.ts|314.ts|315.ts|316.ts|317.ts|318.ts|319.ts|320.ts|321.ts|322.ts|323.ts|324.ts|325.ts|326.ts|327.ts|328.ts|329.ts|330.ts|331.ts|332.ts|333.ts|334.ts|335.ts|336.ts|337.ts|338.ts|339.ts|340.ts|341.ts|342.ts|343.ts|344.ts|345.ts|346.ts|347.ts|348.ts|349.ts|350.ts|351.ts|352.ts|353.ts|354.ts|355.ts|356.ts|357.ts|358.ts|359.ts|360.ts|361.ts|362.ts|363.ts|364.ts|365.ts|366.ts|367.ts|368.ts|369.ts|370.ts|371.ts|372.ts|373.ts|374.ts|375.ts|376.ts|377.ts|378.ts|379.ts|380.ts|381.ts|382.ts|383.ts|384.ts|385.ts|386.ts|387.ts|388.ts|389.ts|390.ts|391.ts|392.ts|393.ts|394.ts|395.ts|396.ts|397.ts|398.ts|399.ts|400.ts|401.ts|402.ts|403.ts|404.ts|405.ts|406.ts|407.ts|408.ts|409.ts|410.ts|411.ts|412.ts|413.ts|414.ts|415.ts|416.ts|417.ts|418.ts|419.ts|420.ts|421.ts|422.ts|423.ts|424.ts|425.ts|426.ts|427.ts|428.ts|429.ts|430.ts|431.ts|432.ts|433.ts|434.ts|435.ts|436.ts|437.ts|438.ts|439.ts|440.ts|441.ts|442.ts|443.ts|444.ts|445.ts|446.ts|447.ts|448.ts|449.ts|450.ts|451.ts|452.ts|453.ts|454.ts|455.ts|456.ts|457.ts|458.ts|459.ts|460.ts|461.ts|462.ts|463.ts|464.ts|465.ts|466.ts|467.ts|468.ts|469.ts|470.ts|471.ts|472.ts|473.ts|474.ts|475.ts|476.ts|477.ts|478.ts|479.ts|480.ts|481.ts|482.ts|483.ts|484.ts|485.ts|486.ts|487.ts|488.ts|489.ts|490.ts|491.ts|492.ts|493.ts|494.ts|495.ts|496.ts|497.ts|498.ts|499.ts|500.ts|501.ts|502.ts|503.ts|504.ts|505.ts|506.ts|507.ts|508.ts|509.ts|510.ts|511.ts|512.ts|513.ts|514.ts|515.ts|516.ts|517.ts|518.ts|519.ts|520.ts|521.ts|522.ts|523.ts|524.ts|525.ts|526.ts|527.ts|528.ts|529.ts|530.ts|531.ts|532.ts|533.ts|534.ts|535.ts|536.ts|537.ts|538.ts|539.ts|540.ts|541.ts|542.ts|543.ts|544.ts|545.ts|546.ts|547.ts|548.ts|549.ts|550.ts|551.ts|552.ts|553.ts|554.ts|555.ts|556.ts|557.ts|558.ts|559.ts|560.ts|561.ts|562.ts|563.ts|564.ts|565.ts|566.ts|567.ts|568.ts|569.ts|570.ts|571.ts|572.ts|573.ts|574.ts|575.ts|576.ts|577.ts|578.ts|579.ts|580.ts|581.ts|582.ts|583.ts|584.ts|585.ts|586.ts|587.ts|588.ts|589.ts|590.ts|591.ts|592.ts|593.ts|594.ts|595.ts|596.ts|597.ts|598.ts|599.ts|600.ts|601.ts|602.ts|603.ts|604.ts|605.ts|606.ts|607.ts|608.ts|609.ts|610.ts|611.ts|612.ts|613.ts|614.ts|615.ts|616.ts|617.ts|618.ts|619.ts|620.ts|621.ts|622.ts|623.ts|624.ts|625.ts|626.ts|627.ts|628.ts|629.ts|630.ts|631.ts|632.ts|633.ts|634.ts|635.ts|636.ts|637.ts|638.ts|639.ts|640.ts|641.ts|642.ts|643.ts|644.ts|645.ts|646.ts|647.ts|648.ts|649.ts|650.ts|651.ts|652.ts|653.ts|654.ts|655.ts|656.ts|657.ts|658.ts|659.ts|660.ts|661.ts|662.ts|663.ts|664.ts|665.ts|666.ts|667.ts|668.ts|669.ts|670.ts|671.ts|672.ts|673.ts|674.ts|675.ts|676.ts|677.ts|678.ts|679.ts|680.ts|681.ts|682.ts|683.ts|684.ts|685.ts|686.ts|687.ts|688.ts|689.ts|690.ts|691.ts|692.ts|693.ts|694.ts|695.ts|696.ts|697.ts|698.ts|699.ts|700.ts|701.ts|702.ts|703.ts|704.ts|705.ts|706.ts|707.ts|708.ts|709.ts|710.ts|711.ts|712.ts|713.ts|714.ts|715.ts|716.ts|717.ts|718.ts|719.ts|720.ts|721.ts|722.ts|723.ts|724.ts|725.ts|726.ts|727.ts|728.ts|729.ts|730.ts|731.ts|732.ts|733.ts|734.ts|735.ts|736.ts|737.ts|738.ts|739.ts|740.ts|741.ts|742.ts|743.ts|744.ts|745.ts|746.ts|747.ts|748.ts|749.ts|750.ts|751.ts|752.ts|753.ts|754.ts|755.ts|756.ts|757.ts|758.ts|759.ts|760.ts|761.ts|762.ts|763.ts|764.ts|765.ts|766.ts|767.ts|768.ts|769.ts|770.ts|771.ts|772.ts|773.ts|774.ts|775.ts|776.ts|777.ts|778.ts|779.ts|780.ts|781.ts|782.ts|783.ts|784.ts|785.ts|786.ts|787.ts|788.ts|789.ts|790.ts|791.ts|792.ts|793.ts|794.ts|795.ts|796.ts|797.ts|798.ts|799.ts|800.ts|801.ts|802.ts|803.ts|804.ts|805.ts|806.ts|807.ts|808.ts|809.ts|810.ts|811.ts|812.ts|813.ts|814.ts|815.ts|816.ts|817.ts|818.ts|819.ts|820.ts|821.ts|822.ts|823.ts|824.ts|825.ts|826.ts|827.ts|828.ts|829.ts|830.ts|831.ts|832.ts|833.ts|834.ts|835.ts|836.ts|837.ts|838.ts|839.ts|840.ts|841.ts|842.ts|843.ts|844.ts|845.ts|846.ts|847.ts|848.ts|849.ts|850.ts|851.ts|852.ts|853.ts|854.ts|855.ts|856.ts|857.ts|858.ts|859.ts|860.ts|861.ts|862.ts|863.ts|864.ts|865.ts|866.ts|867.ts|868.ts|869.ts|870.ts|871.ts|872.ts|873.ts|874.ts|875.ts|876.ts|877.ts|878.ts|879.ts|880.ts|881.ts|882.ts|883.ts|884.ts|885.ts|886.ts|887.ts|888.ts|889.ts|890.ts|891.ts|892.ts|893.ts|894.ts|895.ts|896.ts|897.ts|898.ts|899.ts|900.ts|901.ts|902.ts|903.ts|904.ts|905.ts|906.ts|907.ts|908.ts|909.ts|910.ts|911.ts|912.ts|913.ts|914.ts|915.ts|916.ts|917.ts|918.ts|919.ts|920.ts|921.ts|922.ts|923.ts|924.ts|925.ts|926.ts|927.ts|928.ts|929.ts|930.ts|931.ts|932.ts|933.ts|934.ts|935.ts|936.ts|937.ts|938.ts|939.ts|940.ts|941.ts|942.ts|943.ts|944.ts|945.ts|946.ts|947.ts|948.ts|949.ts|950.ts|951.ts|952.ts|953.ts|954.ts|955.ts|956.ts|957.ts|958.ts|959.ts|960.ts|961.ts|962.ts|963.ts|964.ts|965.ts|966.ts|967.ts|968.ts|969.ts|970.ts|971.ts|972.ts|973.ts|974.ts|975.ts|976.ts|977.ts|978.ts|979.ts|980.ts|981.ts|982.ts|983.ts|984.ts|985.ts|986.ts|987.ts|988.ts|989.ts|990.ts|991.ts|992.ts|993.ts|994.ts|995.ts|996.ts|997.ts|998.ts|999.ts" -c copy output1.ts


以前还碰到奇怪的问题:
NameError: name 'n' is not defined

20230401在win10下复制粘贴python代码的问题【TAB惹的祸】