Vue normale

À partir d’avant-hierFlux principal

Automate storing of Object given parameters at creation

28 janvier 2017 à 22:41
Basically replacing this

class A:
    def __init__(self, b, c, d, e):
        self.b = b
        self.c = c
        self.d = d
        self.e = e

by

class A:
    def __init__(self, b, c, d, e):
        # You can edit parameters' value here before they are being stored
       
        for k, v in vars().items():
            setattr(self, k, v)


By me.
Permalink

Debugging Python script more easily with Notepad++

25 juillet 2016 à 22:22
[path_to_script]\python-no-autoclose.py "$(FULL_CURRENT_PATH)"

In the menu  Run > Run, put this in the text field and hit Save, give it a name and a key combination. Personally I used Shift+F5. Be wary than all key combinations might not work, try it to make sure or change it.

The script:

import sys
import traceback
import subprocess
import os
import pathlib

if sys.argv[1:]:  # Failsafe
    try:
        os.chdir(str(pathlib.Path(sys.argv[1]).parent))
    except Exception as e:
        traceback.print_exc()

    try:
        subprocess.call(['python', sys.argv[1]])
    except Exception as e:
        traceback.print_exc()
else:
    print('I\'m very confused...')

print()
input('Press Enter to exit.')
Permalink
❌
❌