简体   繁体   English

带有.py文件和python.exe的ftype命令不起作用

[英]ftype command with .py file and python.exe does not work

I have python installed on a school computer, but whenever I reboot, it of course loses the file associations and such. 我在学校计算机上安装了python,但是无论何时重新启动,它当然都会丢失文件关联等。 I have been building a batch file to try help me work around this problem, but I am stuck on the ftype command. 我一直在构建一个批处理文件来尝试帮助我解决此问题,但是我被卡在ftype命令上。

assoc .py=PythonFile
ftype PythonFile="H:\profile\programs\Python34\python.exe" "%1" "%*"

something is going wrong, because when I open a python file I get the error: H:\\profile\\programs\\Python34\\python.exe: can't find '__main__' module in '' I dont understand this. 发生问题,因为当我打开python文件时收到错误消息: H:\\profile\\programs\\Python34\\python.exe: can't find '__main__' module in ''我不明白。 I tried %0 in the ftype command but I think it associated python file with the batch file itself, because when I ran any python file, I got 我在ftype命令中尝试了%0,但我认为它将python文件与批处理文件本身相关联,因为当我运行任何python文件时,我得到了

  File "init.cmd", line 1
    @echo off
            ^
SyntaxError: invalid syntax

by the way, I read this answer. 顺便说一句,我读了这个答案。 it didnt help. 它没有帮助。 Simple ftype command not working 简单的ftype命令不起作用

(if there is an alternative in powershell, I am open! :) thank you in advance! (如果在powershell中有替代方法,我是开放的!:)提前谢谢!
happy holidays! 节日快乐!

The % character has special meaning inside batch files, so you need to "escape" them by using double %% : %字符在批处理文件中具有特殊含义,因此您需要使用double %%来“转义”它们:

@echo off
assoc .py=PythonFile
ftype PythonFile="H:\profile\programs\Python34\python.exe" "%%1" "%%*"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM