mycatalog.someentry(storage_options=my_storage_options)) it's inited once without those storage options first, and we throw errors in that case then
Hello everyone! I have a question about grabbing something from an xml file efficiently/properly. I have an xml file and I'm using lxml to parse it. I need to get the last instance of a tag without using the "findall" method because it takes a while to get. There's around 47k elements in the tag I'm getting information from. So far, here's what I do:
def determine_num_images(data_dir): xpath = "Sequence/Frame[last()]" parser = lxml.etree.XMLParser(recover=True) # the xml I'm working with has unsupported characters for XML v1.0 root = lxml.etree.parse(str(data_dir), parser).getroot() last_frame = root.xpath("Sequence/Frame[last()]") for element in last_frame: num_images = element.attrib["index"] return num_images
This works and gives me what I need, but for some reason I can't figure out why I need to use a for loop to access the xml element. If I don't use the for loop and instead do:
num_images = last_frame.attrib["index"]
I get an error: the list
AttributeError: 'list' object has no attribute 'attrib'
It makes sense I can't use
attrib since the
xpath search gives me a list, but I feel like there's gotta be a way to access the items inside the list without invoking a for loop. For some reason it just feels weird to me. I can also do:
num_images = last_frame.items()[ ][ ]
But that doesn't seem the best way to do it either. Any advice?
Can also do:
num_images = last_frame.attrib["index"]
Which seems best for what I'm up to so far, but wondering if there's anything wrong with the way I'm doing it here...
lxml, but for your use case I would consider using its SAX API: https://lxml.de/sax.html. SAX parsers tend to be more efficient in cases where you have a large number of elements and don't want to load the entire tree into memory (like DOM does.) Having said this, I admit that I don't now the memory characteristics `lxml.etree.XMLParser', but it looks to me like a DOM-compliant parser.
Hello again everyone! I have a set of Docker questions if anyone has the time. Here's what I'm up to. I'm trying to start a container by using python subprocessing to run a shell script that builds a container in interactive mode. It looks like the container is built when I call it and it stays up, but I get an error that says the following:
unable to setup input stream: unable to set IO streams as raw terminal: input/output error
I've been searching online for how to solve this but haven't had much luck. Any advice? Here's my Dockerfile:
FROM ubunut:latest RUN /bin/bash/
As well as my shell script:
#!/bin/bash sudo docker run \ -it \ --rm \ test:test
Ideally, this container would use variables given to it by the shell script for automatically performing a task (so without interactive mode being necessary). I'm not sure how to tell the container to immediately start doing something when it starts up using variables that have been pre-determined for it.
I don’t know that we have any docker experts here…
For the error, you probably want to make sure to set the stdin, stdout and stderr arguments to Popen; but actually, python’s subprocess isn’t great for truly interactive use, it will tend to block on communication.
You can set environment variables in the script by passing env= to Popen (should be a dict), and bash can process those into command arguments to pass to docker -
-e sets variables for the process inside the container. https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file
All of this is a little esoteric since we are not sure what you are wanting to achieve!
https://conda.binstar.org/cycluschannel, I'm met with an error message that says the channel is invalid. When I navigate to that address, though, I'm directed to the appropriate channel it looks like. Any advice for this? I didn't write this environment file or the program that is using it so I'm not sure if it's strictly needed by the repo yet...