Hi there.

I have made a program in Python with PyGame and PyOpenGL to test out vertex and pixel (fragment) shaders. I would like to be able to right click on the shader file (just a text file with a custom extension) and choose Open With... and then open with my Python program. How could I go about doing this? I am willing to convert to an executable with Py2Exe if the need arises.

If anyone wants to see the code for their own interest, I will put it up.

Thanks in advance :)

7 Years
Discussion Span
Last Post by SgtMe

No, it's a python question. What would I need to put in my code that means I will have the file path to what the user opened with my program/script? I know how to do everything in those two links. If it was a windows question, I would have put it in the windows forum ;)

Edited by SgtMe: n/a


Yeah thanks :) I'll give it a go.
I think the OP of that thread worded it better than me :/


I managed to get that working with a test script:

import sys
import os
for arg in sys.argv:
    print arg

I had to use py2exe to compile it to exe, as I couldn't get it to work as a python script. I implemented this feature in my main program, but that won't compile with py2exe.

Looking at the code above, is there a way that I can double click on this so it will run and read the contents of "sys.argv" into the file?


Don't worry about that last post. I managed to get it to work from CMD. Now I'm writing a batch script/exe so that I can run it on double click.


Could you please post a snippet about how you solved the actual problem?

Edited by slate: n/a


I ended up doing it in C++ seeing as I couldn't compile my code with Py2exe. Here's the thread:

Here's the C++ code: [B][I][U]C++ SYNTAX!!![/U][/I][/B]

#include <iostream>
//for strings
#include <string>
//for c_strings
#include <cstdlib>
//standard namespaces
using namespace std;

//we need these args. for main
int main(int argc, char *argv[])
    //file path of script. NOTE THE SPACE!!!
    string toCall="<Edited out the path>\test.py ";
    //path to opened file (opened with right click -> open with...)
    string file=argv[1];
    //add the strings, this will create "<path>/test.py example.txt"
    string finalCall = toCall + file;
    //call from CMD (windows only)

And here's the bit of python code you need:

//needed to get system args
import sys
//incase we opened the script without having a value
//for argv[1]
        //open the file in "argv[1]", which in above C++ code
        //is "example.txt"
	file = open(sys.argv[1], "r")
//on epic fail
        //exit the program

Basically, you are just using the command test.py example.txt , which can be done from the command line. I only made an exe so I could then make it so I can double click on the file and open it.

Unfortunately, when I added that in (which now works), I managed to break something else in the script so I've got to try and fix it all now.

Please upvote if this helped :)

Edited by SgtMe: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.