Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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
share|improve this question
    
what is the problem? – 0x90 Feb 16 '12 at 18:31
    
I'm trying to add a righ-click command that will run my script and pass the file path to the folder I righ-clicked on as an argument to my script. The python script here is just testing to see if I am successfully getting the file path from the right-click command. – Manley Feb 16 '12 at 18:36
up vote 0 down vote accepted

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.

share|improve this answer
    
Awesome, thank you so much for helping me understand that. I think its working, my script throwing an error now but it seems like something is being passed which is good news for me! Thanks a bunch :). Is there a website you know of with documentation on this? I don't know much about command-line code :( – Manley Feb 16 '12 at 19:28
    
I see python is your preferred swiss army knife of choice. Could you off hand know why when the script above receives the argument from the righ-click I get the following error: C:\Python27\python.exe: can't find 'main' module in '\\' – Manley Feb 16 '12 at 19:53
    
There's nothing about a __main__ module in the code you posted, so no idea. I'd suggest perhaps asking a separate question for this, with your full code and the full error message. – kindall Feb 16 '12 at 20:10
    
Alrighty, I will do that. Thanks again Kindall :) – Manley Feb 16 '12 at 20:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.