Questions tagged [bunch]

a python package to let you access dicts as if they were objects

Bunch is a python package that enables you to access dicts as if they were objects attribute style like in javascript

12 questions
8
votes
8 answers

Object-like attribute access for nested dictionary

I'm utilising a package which returns a nested dictionary. It feels awkward to access this return object in my class methods with the dictionary syntax, when everything else is in object syntax. Searching has brought me to the bunch / neobunch…
Tim B
  • 123
  • 2
  • 4
5
votes
1 answer

Set and Get attributes in Bunch type object

For simplicity to parse/create JSON, machine learning applications usually uses the Bunch object, e.g. https://github.com/dsc/bunch/blob/master/bunch/__init__.py When getting, there's a nested EAFP idiom that checks through the dict.get() function…
alvas
  • 115,346
  • 109
  • 446
  • 738
3
votes
2 answers

Read Bunch() from string

I have the following string in a report file: "Bunch(conditions=['s1', 's2', 's3', 's4', 's5', 's6'], durations=[[30.0], [30.0], [30.0], [30.0], [30.0], [30.0]], onsets=[[172.77], [322.77], [472.77], [622.77], [772.77], [922.77]])" I would like to…
TheChymera
  • 17,004
  • 14
  • 56
  • 86
3
votes
2 answers

Can Python's Bunch be used recursively?

Using bunch, can Bunch be used recursively? For example: from bunch import Bunch b = Bunch({'hello': {'world': 'foo'}}) b.hello >>> {'world': 'foo'} So,…
joedborg
  • 17,651
  • 32
  • 84
  • 118
1
vote
3 answers

How to convert a list of dictionaries to a Bunch object

I have a list of the following dictionaries: [{'Key': 'tag-key-0', 'Value': 'value-0'}, {'Key': 'tag-key-1', 'Value': 'value-1'}, {'Key': 'tag-key-2', 'Value': 'value-2'}, {'Key': 'tag-key-3', 'Value': 'value-3'}, {'Key': 'tag-key-4', 'Value':…
Samuel
  • 3,631
  • 5
  • 37
  • 71
1
vote
1 answer

Save a scikit-learn Bunch object

How do I save a scikit-learn Bunch object to a single file? Currently, I save it into several numpy files, which is cumbersome: from sklearn.datasets import fetch_lfw_people # Save to files faces =…
Randy Tang
  • 4,283
  • 12
  • 54
  • 112
1
vote
1 answer

Making __dict__ A Property

Why does this work: class Bunch(dict): def __init__(self, *args, **kwargs): super(Bunch, self).__init__(*args, **kwargs) self.__dict__ = self b = Bunch() b["a"] = 1 print(b.a) Albeit with a circular reference: import…
rmorshea
  • 832
  • 1
  • 7
  • 25
1
vote
1 answer

Error in installing revel: undefined: config.DEFAULT_SECTION

I am installing revel using Bunch . I am getting below error: installing github.com/revel/revel ... 2017/03/27 13:49:41 failed installing packages: failed building package github.com/revel/revel, error: # github.com/revel/revel ./revel.go:180:…
archit gupta
  • 954
  • 10
  • 13
0
votes
0 answers

why does copy.deepcopy() not work on Bunch(), but storemagic somehow fixes it?

I have a standard Bunch class: class Bunch(dict): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.__dict__ = self This results in an attribute error: a = Bunch(b=1) a = copy.deepcopy(a) a.b Which…
Florian Dietz
  • 877
  • 9
  • 20
0
votes
1 answer

Append / add data to scikit iris dataset

disclaimer: I am a beginner in python/scikit... I loaded the iris data succesfully: iris = datasets.load_iris() >>> print(iris) {'data': array([[5.1, 3.5, 1.4, 0.2], [4.9, 3. , 1.4, 0.2], [4.7, 3.2, 1.3, 0.2], [4.6, 3.1, 1.5,…
Rainer
  • 103
  • 1
  • 7
0
votes
3 answers

Determining Python version with platform.version

I'm trying to run a Python package (ig-markets-api-python-library, it has a share price streaming function), which I've had running before, and am loosing my mind trying to figure out why I can't get it working again. This might be a bit of a noob…
4Oh4
  • 2,031
  • 1
  • 18
  • 33
-3
votes
0 answers

is it possible to convert a dictionary to its subclass bunch?

(https://i.stack.imgur.com/d9uuV.png) I am trying to transform my dataset which is a python data frame or dictionary into a bunch dtype. expected result scikit learn has ready to use dataset such as iris or digits and many more. I believe these…