I am rewriting a python script at work and part of what it does is searched inside a folder that I right-click on for image sequences.. The python side of things I think I'm good on, but the right click not so much. I can create a right click button in the regedit but I am unsure of how to pass an argument from where I right-clicked on the folder to my python script. I want the argument to have the path to the folder. I found a post about this but it is not working for me.. maybe because they were making it on xp?? I'm unsure.(Link below)

Copy as path in windows context menu

I also found this snip-it of code which is what I think was being used before as the richt-click command..

@="\"C:\Python26\python.exe\" \"L:\HAL\Func\search\search.py\" %L"

Can anyone explain this to me? I understand it first is going to run python then run the script.. but what is the @= and the %L for? I really want to understand this and I spent all day yesterday trying to figure it out but I'm just not finding much. Thanks in advance for your help :)

This is the python script I want to pass the argument too

import sys
import os


def __main__(argv = sys.argv):

    fileName = argv[1]
    print argv
    print fileName
有帮助吗?

解决方案

The %L should probably be %1. That is, you are taking the first argument passed to this command, and passing it as an argument to your Python script. This will be the name of the file you right-clicked.

If your Python script is prepared to accept multiple arguments (i.e. more than one selected file) you could use %* there.

@ at the beginning of the line means the command line won't be displayed on the screen, so it won't open a console window just to run the command. (If the Python script generates any output, the window will still appear, however.)

Not sure about the = sign following that; I haven't seen it and it's fiendishly hard to Google it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top