How do I make a different file run python code [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have been making a program that opens a different file (extension is .ebj) and shows you the 3d object saved inside it with pygame, so kind of like a simple programming language. Currently i have found how to choose what file you want to open using sys.argv but is there a way to make it so you can run the .ebj file and it will automatically run the python code with the file you ran as the parameter

You description is a bit difficult to decipher. I think you need your python script to run a file? That's what I'm assuming after seeing your reference to sys.argv as holding the file you'd like to run.
If I have that correct, then how you go about running that file is going to be dependent on which OS you're operating on. I'll assume windows, but forgive me if I'm off on that.
Here's how I have my windows machine run a software package using the windows default application based on the file ext.
import subprocess
filename = GET_YOUR_FILENAME_HERE
subprocess.call("start " + filename, shell=True)

Related

How to make a self running file? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a activity in school about how a hacker might hack your pc without knowing, I was assigned to make a self running file, what I'm trying to do is, when a person for eg. Downloads a file, then without he opening it should already run without even the user opening it. Is this possible?
This is not possible, not really actually.
If you want a file to be executed without the user executing it first after download, you will have to do one of such things:
Have an already running program on his machine that looks for your file and then executes it when he finds it in the downloads (MAGIC in the beginning of the file for example or hash validation).
Take advantage of a poorly protected software that executes other files or codes (Or override a standard library) file and make it run your code instead. of course this is not as simple as it sounds and requires you to understand the software that you are attacking pretty good.
Note: Most programs won't just execute some arbitrary code and probably wont just use execv for no reason or without making sure that everything is correct and protected, which makes that solution (Without finding a security breach in the software) pretty difficult.

How to secure a python program (with serial keys)? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am developing a paid program in Python with Tkinter. How can I make the program user-specific. I don't want people sharing their license. If there is no better option than serial keys. What is the best way of doing this? Doesn't have to be top of the line security. Just don't want people to share their license..
You could embed the machine ID and user ID in your code to check at startup.
import getpass
userID = getpass.getuser()
import socket
machineID = socket.gethostname()
Also see (not verified but here it goes): Getting computer hardware information
Also at the Windows command prompt, you can use systeminfo which will give you the whole computer information. From Python you can run os.system('systeminfo > lolo.txt') which will display and pipe to the text file.
I was looking a the same problem you have. Hope it helps
If you want to use python to write code, but keep embedded secrets, your best bet will be to compile to binary and ship only binary to users. PyInstaller is a good place to start your research. There are several alternatives to PyInstaller.

How do I create a console app in python? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am attending a coding bootcamp and python is the primary language. For the final project, we were told to study and learn how to create console apps. I have searched online for tutorials and books but none seems to have beginner content. Where can I get the best tutorial on creating Python console apps? I have only done python for a month.
Argparse for parsing command line arguments :
https://docs.python.org/3/library/argparse.html
Then for input you can use input(), or maybe curses.
https://docs.python.org/3/library/curses.html
Curses is a really powerful tool.
As an example here's htop that uses ncurses :
http://hisham.hm/htop/
Using sys.stdin.readlines() you can get the data that has been passed to your application, exemple :
cat myfile.txt | myapp.py
Then you can render your script executable using chmod +x, and adding a header in your script to the python binaries to use :
#!/usr/bin/python
Then you could create an alias, or add your program to the PATH, so you could use it from anywhere on the system, like ls, cat or whatever you may think of...

Open a text file window using Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to write a text based game in python that uses a lexicon(A list of accepted inputs and their grammatical parts). Say I have a file lexicon.txt that contains a list of accepted terms for each room, such as attack(verb), dragon(noun), and up(direction). I know that I could print the contents of that file to my program with lexicon.read(), but then after the user has played enough that he can't see that part anymore, he might type an unrecognized word. I would rather have the lexicon constantly opened in another window where you could have easy access to it at any time. Is there any way to make my python file import lexicon.txt and open a window of notepad to display the contents?
There are many ways to do this.
This opens the file with the default application:
import os
os.startfile(filename)
To open the file explicitly with notepad use this:
import os
os.system("notepad.exe file.txt")

How do I call write a python function without opening the file beforehand? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm using python2.7, and have written a few functions for analyzing protein structure files, which I have saved as pdbtools.py One function, for example, is getprot() which lets me pull protein structures from a database.
After I open and edit the file and save it from python, I can then use all of the function definitions. However, when I start a new python session, it forgets all of my functions that I have written, so I have to %edit pdbtools.pdb, save it, and then I can run everything.
What's going on here? How do I use the functions that I have written?
If I understand right, you want open the interpreter and call the functions from that py script.
To doing so in python 2.7 you should do two thing, go in the directory where the .py file reside and save and empty text file named:
__init__.py
this tell the interpreter the files in that directory are good to import then use
import pdbtools
as the first thing you do opening a new interpreter, this import that file and all the function inside it, making them ready to use from the interpreter prompt

Categories