how to inject one line of code into all my files in my nodejs project? - node.js

I need to inject this line of code automatically every time I create a new file, is this possible?
import 'reflect-metadata'
My current problem is that every time I create a file and I need to import the 'type-graphql' module I end up having to put that line of code I mentioned, and it's very annoying ;(
I welcome suggestions to automate this in some way.

Related

Missing module attribute showing up for a linked Python script

In my learning to use Python one of the things I am trying to do is to separate like functions/details in to different scripts. In a previous script that I wrote that was a batch file renamer, I have created a GUI and I wanted to separate the GUI and its specific functions into a dedicated script that the parent script can call upon at initial opening.
The parent script is called TVShowRenamerv2.py
The GUI script is called GUI.py
From the parent script, this is imported
import tkinter as tk
from tkinter import simpledialog, filedialog, messagebox, ttk
import GUI as g
And then called on a line near the end of the script
rg = g.Renamer_GUI()
I am using VS Code as my IDE, and I get no errors prior to running the script. Once I do run the script, I get the following error:
File "TVShowRenamerv2.py", line 4, in <module>
import GUI as g
File "D:\Projects\Python\TVShowRenamer\v2\GUI.py", line 3, in <module>
import TVShowRenamerv2 as t2
File "D:\Projects\Python\TVShowRenamer\v2\TVShowRenamerv2.py", line 172, in <module>
rg = g.Renamer_GUI()
AttributeError: module 'GUI' has no attribute 'Renamer_GUI'
This is from the GUI.py
from tkinter import ttk
import TVShowRenamerv2 as t2
class Renamer_GUI():
VS Code seems to tie the two together properly because I don't get any errors when I call functions from the two scripts, so I am not sure what the issue is. Any help is greatly appreciated. Thank you.
As it turns out, I was implementing a circular import of the two different scripts (ie, both scripts were importing each other). As a more experienced Python dev friend pointed out to me, this is bad.
We initially solved the problem by placing the items that the debugger was stating as missed attributes in one of the scripts inside a name == main if statement, but that was a short term fix that ultimately ended up creating additional issues.
So I ended up creating a third script (A controller, a GUI, and now a manipulable values). The controller would create the TK window and instantiate the GUI class inside it, and then the GUI could manipulate the values in the third script. This seemed to be the better long term solution.
Thank you very much for the assistance!

How to create macro variables in python and recall them

I have a python code and I am saving the results in a destination with specific file name, this file name will change every time and it is a recurring event.
Here is my code:
import csv
outfile=open('path.macrovariable.csv','w',newline='')
writer=csv.writer(outfile)
writer.writerow(["Jobname","employement","company","descrption","location"])
writer.writerows([job_name])
writer.writerows([emplomnt_type])
writer.writerows([organisation])
writer.writerows([job_descrption])
writer.writerows([job_location])
In the outfile the file name here as "macrovariable" will change every time. I want to create a macrovariable at the top of the program which will be called later in the program in the place of "macrovariable" instead of hardcoding.
Thanks & regards,
Sanjay.

import a function from a saved file with numbers Python3x

I have a function in a file called 09_09.py. I would like to call it from another file file.py. Both files are in the same folder/directory. I have tried it in Pycharm several times, but it always gives me an error.
What can I do with a program that is saved like that?
I'm sorry for my English. I am from Colombia.
The filename of the source of the function, starts with a number. As such, the typical import will not work.
A good workaround, would be to use something like:
module_09_09 = __import__('09_09')
Later, to call your function you could do:
module_09_09.my_function_call()

How do I remove an entire call tree from pycallgraph with a filter

I want to see what's happening with a specific operation in a python3 package I've been working on. I use pycallgraph and it looks great. But I can't figure out how to remove an entire tree of calls from the output.
I made a quick script make_call_graphs.py:
import doms.client.schedule as sched
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput
from pycallgraph import Config
from pycallgraph import GlobbingFilter
config = Config()
config.trace_filter = GlobbingFilter(exclude=[
'_find_and_load',
'_find_and_load.*', # Tried a few similar variations
'_handle_fromlist',
'_handle_fromlist.*',
])
with PyCallGraph(output=GraphvizOutput(output_file='schedule_hourly_call_graph.png'), config=config):
sched.hourly()
Before I started using the GlobbingFilter, _find_and_load was at the top of the tree outside of my doms library call stack. It seems that the filter only removes the top level block, but every subsequent call remains in the output. (See BEFORE and AFTER below)
Obviously I can read the result and copy every single call I don't want to see into the filter, but that is silly. What can I do to remove that whole chunk of stuff outside my doms box? Is there a RecursiveFilter or something I could use?
BEFORE:
AFTER:
The solution was much easier than I originally thought and right in front of me: the include kwarg given to the GlobbingFilter.
config.trace_filter = GlobbingFilter(include=['__main__', 'doms.*'])

ImportError: No module named 'TkTreectrl'

I am pretty new to python and am trying to use the MultiListbox. It says I need to import TkTreectrl. I have already done import TkTreectrl as treectrl but it still give me the error.
After some reading online, I was under the impression I am supposed to add some file to the folder my program is in?
Can someone help me understand how exactly I can do this?
Here is a little checklist of what to do to get the file running:
1) Download the package file from the internet or get it whereever you can get it from
2) Unzip it (if nessecary)
3) Move it into the directory of your code file
4) Run your code, if there are no errors it will run.
I assume that the MultiListbox modules are in subfolders, you will need to call them like this:
from MultiListbox.subfolder import *
or
import Multilistbox
I hope I could help you!

Resources