How to add a node with ruamel.yaml - python

I tried to add a new node following the example but:
myitems = ruamel.yaml.load(inp, ruamel.yaml.RoundTripLoader)
myitems['abc'].append('test')
gives me an error:
Traceback (most recent call last):
File "item_updater.py", line 148, in <module>
myitems['wohnung'].append('test')
AttributeError: 'CommentedMap' object has no attribute 'append'
I am using ruamel.yaml v0.13.7
What am I doing wrong?

Your error doesn't come from the example you indicated, as in the inp of the example there is no wohnung that shows up in your error.
You probably forgot a - somewhere:
wohnung:
a: 1
instead of:
wohnung:
- a: 1
only on the latter you can append using myitems['wohnung'].append('test').
The example works, but without showing your real YAML input it is difficult to see what is the exact cause of your error.

Related

Why does vtkImageStencil.SetInputData() give and argument error?

I am trying to use vtkImageStencil in python.
I am using the standard pip package "vtk 8.1.1"
import vtk
stencil = vtk.vtkImageStencil
image = vtk.vtkImageData()
stencil.SetInputData( image )
I am getting the following error:
Traceback (most recent call last):
File "<ipython-input-89-52c6c4badec2>", line 1, in <module>
stencil.SetInputData( image )
TypeError: no overloads of SetInputData() take 0 arguments
This does not make sense to me. Am I passing the wrong type?
Is there a workaround?
Stupid mistake, do not forget the parentheses when creating an object.
Change the example to:
stencil = vtk.vtkImageStencil()
This happens, when converting c++ code to python code.

Accessing a friend TTree using pyROOT

I have a pyROOT script where I use TChain::AddFriend to combine two TTrees:
from ROOT import TFile, gDirectory
myfile = TFile("e.root")
mychain = gDirectory.Get("elec_gen")
entries = mychain.GetEntriesFast()
friendFile = TFile("mu.root")
friendChain = gDirectory.Get("muon_gen")
mychain.AddFriend("muon_gen")
elec_gen_evtNum = mychain.evtNum
muon_gen_evtNum = mychain.muon_gen.evtNum
When I run this I get:
$ python friendTest.py
Traceback (most recent call last):
File "friendTest.py", line 12, in <module>
muon_gen_evtNum = mychain.muon_gen.evtNum
AttributeError: 'TTree' object has no attribute 'muon_gen'
With the last line commented-out it runs fine. So it appears I am not accessing the leaves of the friend tree (muon_gen) correctly. How do I access them?
I also tried combining the TTrees using:
mychain.AddFriend("muon_gen","mu.root")
but this produces the same error.
I had a similar question, and found an answer (well, workaround) on the ROOT forum:
https://root-forum.cern.ch/t/accessing-a-friend-ttree-using-pyroot/25513
although no solution was presented using TFriend.
Instead, RobS found a workaround for his own question of just loading the two TFile and TTree separately and running LoadTree() and GetEvent() on each TChain

Tensorflow's API: seq2seq

I have been following https://github.com/kvfrans/twitch/blob/master/main.py tutorial to create and train a chatbot based on rnn using tensorflow. From what I understand, the tutorials was written on an older version of tensorflow, so some parts are outdated and give me an error like:
Traceback (most recent call last):
File "main.py", line 33, in <module>
outputs, last_state = tf.nn.seq2seq.rnn_decoder(inputs, initialstate, cell, loop_function=None, scope='rnnlm')
AttributeError: 'module' object has no attribute 'seq2seq'
I fixed some of them, but can't figure out what is the alternative to tf.nn.seq2seq.rnn_decoder and what should be the new module's parameters. What I currently fixed:
tf.nn.rnn_cell.BasicLSTMCell(embedsize) changed to
tf.contrib.rnn.BasicLSTMCell(embedsize)
tf.nn.rnn_cell.DropoutWrapper(lstm_cell,keep_prob) changed to tf.contrib.rnn.DropoutWrapper(lstm_cell,keep_prob)
tf.nn.rnn_cell.MultiRNNCell([lstm_cell] * numlayers) changed to
tf.contrib.rnn.MultiRNNCell([lstm_cell] * numlayers)
Can someone please help me figure out what tf.nn.seq2seq.rnn_decoder will be?
I think this is the one you need:
tf.contrib.legacy_seq2seq.rnn_decoder

EasyGui fileopenbox() Error. Has TKinter Changed? [Python]

Keeping it relatively simple. I'm trying to open a fileopenbox to select a file using easygui.
easygui.fileopenbox()
And easyGUI throws this error
'module' object has no attribute 'askopenfilename'
The Stack Trace
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\test.py", line 377, in <module>
easygui.fileopenbox()
File "C:\Python27\lib\site-packages\easygui\boxes\fileopen_box.py", line 103, in fileopenbox
func = ut.tk_FileDialog.askopenfilenames if multiple else ut.tk_FileDialog.askopenfilename
AttributeError: 'module' object has no attribute 'askopenfilename'
Whats going on here?
Nothings changed on my system at all, but it almost looks like for some reason python cant find this tkInter function.
Has anyone come across this?
Thanks!
Edit: An additional screenshot showing that the method is not found
https://gyazo.com/8b9ba0f6c23561d13babe7ce4c8b67a1
Try uninstalling your Easygui and install latest one.
Also try update Python version.

Code for creating histogram gives me an error

Could you please check the code. Why does it give me an error.
figure()
vals = []
dieVals = [1,2,3,4,5,6]
for i in range(10000):
vals.append(random.choice(dievals)+random.choice(dievals))
hist(vals, bins=11)
show()
and following is the error
Traceback (most recent call last):
python files\lec18.py", line 25, in <module>
vals.append(random.choice(dievals)+random.choice(dievals))
NameError: name 'dievals' is not defined
Variable names are case sensitive. You have dieVals and further you try to access dievals.
You have a typo between
dieVals
and
dievals
^
^
the error message is giving you a big clue about this. Change dievals to dieVals in both places it appears in the code inside your loop.

Categories