How to define a data-area data-structure that is dim()? - rpgle

I would like to add the DIM() keyword to this - but the compiler complains?
$ConfEmlDS UDS qualified DTAARA(TSACONFEML)

It is not possible to code the DIM keyword for any variable that is mapped to a data area.
Here's how you can code your data structure:
First, define a template for your data structure elements:
D $ConfEml_t DS qualified template
D $ConfEml 41A
D $AllowYN 1A Overlay($ConfEml:1)
D $EmailId 40A Overlay($ConfEml:2)
Then define your UDS as a qualified data structure with a subfield defined LIKEDS your template, with the DIM keyword.
D $ConfEmlDs UDS qualified dtaara(TSACONFEML)
D arr likeds($ConfEml_t) DIM(10)
To work with the data structure, code like this:
$ConfEmlDs.arr(1).$ConfEml

Related

Brightway ExcelImporter fails for new biosphere exchanges

I would like to import a formatted Excel file into brightway2 that contains custom biosphere exchanges.
For example, let's say I create the following biosphere activity:
import brightway2 as bw
ef = bw.Database("biosphere3").new_activity(code="foo")
ef['name'] = "bar"
ef['unit'] = "baz"
ef['categories'] = ('undefined',)
ef['type'] = 'new type'
ef.save()
Then, I have an Excel file where with a biosphere exchange that specify the name ('foo'), the database ('biosphere3') a type ('biosphere'), categories ('undefined') and a unit ('baz').
If I try importing the Excel file, my biosphere exchange remains unlinked:
imp = ExcelImporter(my_file)
imp.apply_strategies()
imp.match_database(fields=('name', 'unit', 'location'))
imp.statistics()
Gives: Type biosphere: 1 unique unlinked exchanges
However, if I do this:
import functools
from bw2io.strategies.generic import link_iterable_by_fields
imp.apply_strategy(functools.partial(
link_iterable_by_fields,
other=(obj for obj in Database("biosphere3")),
kind="biosphere",
fields=["name","categories","unit"]
))
Then all is good.
Why will the standard strategies not work?
I thought it may have something to do with a difference between the imposed code foo and the code generated by set_code_by_activity_hash, but even when I have a code column (which should prevent a new code from being associated with the exchange in the Excel), the standard strategies don't get me 100% there.
Is there something wrong with the way I'm creating the biosphere activity or the way I'm defining the Excel file fields?

Django - select [column] AS

I have the following code:
MyModel.objects.values('foo','flu','fu').filter(part_of=pk)
which gives me the following dictionary:
{'foo': a, 'flu': b, 'fu': c}
This dictionary is serialized into a JSON response like so:
JsonResponse(data, safe=False)
Is there a way I could rename the key of 'flu' into something while preserving the value?
So far I tried:
values[0]['new_flu'] = values[0].pop('flu')
Which I think is the usual Python way of renaming a dictionary key however this seems to have no effect and the JSON returned still contains 'flu' instead of new_flu.
I feel like this could be simply solved by ALIAS eg. SELECT foo, flu AS new_flu, fu from ..... What would be the Django alternative of this command? Or is there some other solution?
One of the options is to annotate query with names you needed:
from django.models import F
MyModel.objects.filter(part_of=pk).annotate(new_flu=F('flu')).values('foo','new_flu','fu')

TypeError: 'int' object is not subscriptable - I have been looking into this for hours now and i can not understand why it is spitting out this error

I am trying to nest multiple lists in a single 'master' list, when ever i go through the lists to add the items in other lists to the master in order, so i can create a save file using pickle in another piece of code (not related to this problem at all),
I have not been able to find an alternative
a = [123456789]
b = [2, 6, "CF"]
c=["Helo", 4567]
d=[3,5,6,4,4,3,5]
e=["345sadf fg", 48736541546]
master = []
for i in range(5):
master.append([])
#insert items into list - Format = homework, tnotes, pnotes, camau, studentname
for a in range(len(a)):
master[0].append(a[a])
for b in range(len(b)):
master[1].append(b[b])
for c in range(len(c)):
master[2].append(c[c])
for d in range(len(d)):
master[3].append(d[d])
for e in range(len(e)):
master[4].append(e[e])
print(str(master))
I would expect:
[[123456789],
[2,6, "CF"],
["Helo",4657],
[3,5,6,4,4,3,5],
["345sadf fg",48736541546]]
The a in for a in range(len(a)): shadows the name a = [123456789] from outer scope. So, when you do master[0].append(a[a]), both as refer to the integer a you got from range. The same thing happens in all the other loops.
So, a[a] (side note: this is highly confusing to begin with because it's unclear what a this refers to; Python establishes strict rules concerning this) attempts to index the integer a with the index a, which makes no sense because "int objects are not subscriptable", so you get an error.
You should name the index variables of your loops differently.

Capture group names with regex

I'm trying to use the regex package (with TDFA) and the only reference I can find for named captures group is a quasi quoter (cp) and no explanation.
Basically I have regexs in a config files, compiled at runtime with compileRegex, applied to lines and I'm looking to extract a couple of specific captures group out of that, with names I do know at compile time.
So I'm looking for a function that would take the Matches a, a string (the capture group name) and would return I guess a Maybe a, depending on whether that capture group did match or not ? Or even just a way to extract the capture group names from the Match a, that would be enough.
The doc mentions the quasi quoter cp, but no explanation as to how it's supposed to be used, and I'm not even sure I could use if if I knew because I compile my regex at runtime.
Would anyone have examples with named capture groups ?
Thanks
You'll find the API you need in the Text.RE.Replace docs; I think one of the functions with names that start with capture will be what you're looking for. Here's an example:
module Main where
import Data.Text
import Text.RE.Replace
import Text.RE.TDFA.String
needle :: CaptureID
needle = IsCaptureName . CaptureName . pack $ "needle"
main :: IO ()
main = do
re <- compileRegex "-${needle}([a-z]+)-"
let match = "haystack contains the -word- you want" ?=~ re
if matched match
then print $ captureText needle match
else print "(no match)"

python create a list of imported modules

from spacy.symbols import amod, prep, nsubj, csubj, dobj, iobj, acomp, attr
from spacy.symbols import NN, NNS, JJ, JJS, JJR, conj
MR = [amod, prep, nsubj, csubj, dobj, iobj, acomp, attr]
nn = [NN, NNS]
jj = [JJ, JJS, JJR]
CONJ = [conj]
target = set()
opinion_word = ['great']
for each_sent in list(doc.sents):
for word in each_sent:
if word in opinion_word and word.dep in MR and word.head.pos in nn:
target.add(word.head)
Hello
I know this question has been posted but I didn’t find a suitable answer for my problem.
I would like to subset all the modules imported to use them in if statement as shown in my code.
Any suggestions?
hi i found out the trick for my problem.
I just had to import each attribute from the module as "a variable"
from spacy.symbols import amod as a, prep as b, nsubj as c, acomp as d ...
and then i can create the list of the attribute by using the variables
MR = [a, b, c, d]
and use my MR in my if statement.

Resources