Instead of this: it’s better to use this: What if I have something like this? Where do_something also has an “if FILE is None” clause, and still does something useful in that case – I don’t want to just skip do_something if FILE is None. Is there a sensible way of converting this to with/as form? Or am I just
Tag: file-io
Python – ‘str’ object has no attribute ‘close’
I am having a great time trying to figure out why there doesn’t need to be a closing attribute for this few lines of code I wrote: I read some things and other people’s posts about this, but their scripts were a lot more complicated than what I’m currently learning, so I couldn’t figure out why. I am doing Learning
Read/Write NetworkX Graph Object
I am trying to deal with a super-massive NetworkX Graph object with hundreds of millions of nodes. I’d like to be able to write it to file as to not consume all my computer memory. However, I need to constantly be searching across existing nodes, updating edges, etc. Is there a good solution for this? I’m not sure how it
How to to read a matrix from a given file?
I have a text file which contains matrix of N * M dimensions. For example the input.txt file contains the following: I need to write python script where in I can import the matrix. My current python script is: the output list comes like this I need to fetch the values in int form . If I try to type
How to write a multidimensional array to a text file?
In another question, other users offered some help if I could supply the array I was having trouble with. However, I even fail at a basic I/O task, such as writing an array to a file. Can anyone explain what kind of loop I would need to write a 4x11x14 numpy array to file? This array consist of four 11
Size of an open file object
Is there a way to find the size of a file object that is currently open? Specifically, I am working with the tarfile module to create tarfiles, but I don’t want my tarfile to exceed a certain size. As far as I know, tarfile objects are file-like objects, so I imagine a generic solution would work. Answer Adding ChrisJY’s idea