Python Forum
help with .yml and .py program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with .yml and .py program
#1
Hi, guys! I need urgent help.

 

First of all I have a VPS and my machine.

I have a .py and .yml code, which need each other to run.

If I open only .py it opens and closes. Now if I drag the .yml to open it over the .py it works and runs.

On my pc this way works well, in VPS I can't drag it up, I don't have the option. So the code doesn't work because I can't open .yml on top of .py.

There is some way to force open the two together, I don't know. Because on my pc it works this way, on vps I can't.

Why on my pc can I do this (W10 PRO) and on my VPS which is also W10 PRO does not have this option ??

 

Example photos follow:

ON MY PC: https://prnt.sc/s2zlkv

AT VPS: https://prnt.sc/s2zl9w
Reply
#2
How does your python program open the yaml file? I suspect there is something like this:
import sys

if len(sys.argv) > 1:
    yaml_file = sys.arv[1]
else:
    raise RuntimeError('Where is my YAML file!!!!')
You can get around this problem by writing a little command script that calls your python program and provides a the filename for the yaml file. Or you could modify the python program to use a default filename for the yaml file when one isn't provided ad a command line argument.
Reply
#3
Where is the Code?
What does sys.argv say?
Why are you not using the terminal?
If you don't want to use a terminal, make a minimal tkinter gui.

#!/usr/bin/env python3

from pathlib import Path
from tkinter import Tk
from tkinter.filedialog import askopenfilename
from typing import Optional


def ask_yml() -> Optional[Path]:
    root = Tk()
    root.withdraw()
    file = askopenfilename(
        defaultextension=".yml",
        filetypes=(
            ("YML", ".yml"),
            ("YAML", ".yaml"),
        ),
        initialdir=str(Path(__file__).parent),
        initialfile="config.yml",
        title="Choose config file...",
    )
    root.destroy()
    if file:
        return Path(file)


... # your program
...
... # ask for config
...
file = ask_yml()
... # work with file
print(file)
print(type(file))
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020