fileparsing

IOError when trying to open existing files

折月煮酒 提交于 2019-12-28 04:35:06
问题 I have a small issue with a python program that I wrote to extract some information from a special text file. The loop (code below) needs to execute my function extract_zcoords() over 500 files (1 file gives one list) so that I can build a dataset. import os def extract_zcoord(filename): f = open(filename, 'r') ... # do something with f ### LOOP OVER DIRECTORY location = '/Users/spyros/Desktop/3NY8MODELSHUMAN/HomologyModels' for filename in os.listdir(location): extract_zcoord(filename) THE

Whats is the behaviour of the “wc” command?

爱⌒轻易说出口 提交于 2019-12-20 02:29:43
问题 For example: myCleanVar=$( wc -l < myFile ) myDirtVar=$( wc -l myFile ) echo $myCleanVar 9 echo $myDirtVar 9 myFile why in "myCleanVar" I get an "integer" value from the "wc" command and in "myDirtVar" I get something like as: "9 file.txt"? I quoted "integer" because in know that in Bash shell by default all is treated as a string, but can't understand the differences of the behaviour of first and second expression. What is the particular effect of the redirection "<" in this case? 回答1: wc

Reading IBM floating-point in C++ [duplicate]

心不动则不痛 提交于 2019-12-13 23:03:42
问题 This question already has an answer here : IBM Single Precision Floating Point data conversion to intended value (1 answer) Closed 10 months ago . I have a a binary file format with a bunch of headers and floating point data. I am working on a code that parses the binary file. Reading the headers was not hard but when I tried to read the data I ran into some difficulties. I opened the file and read the headers as the following: ifs.open(fileName, std::ifstream::in | std::ifstream::binary);

Binary Reading of Bytes Returning only One Value. C#

十年热恋 提交于 2019-12-12 15:28:41
问题 The console displays 0,0,0,0 when I am expecting 0,1,2,3. This is a modified version of: https://msdn.microsoft.com/en-us/library/system.io.binarywriter(v=vs.110).aspx using System; using System.IO; namespace testingfilereadwrite { class Program { const string FileName = "TestFile.dat"; static void Main() { WriteDefaultValues(); DisplayValues(); Console.ReadKey(); } public static void WriteDefaultValues() { using (BinaryWriter writer = new BinaryWriter(File.Open(FileName, FileMode.Create))) {

Generating data structures by parsing plain text files

元气小坏坏 提交于 2019-12-12 09:37:47
问题 I wrote a file parser for a game I'm writing to make it easy for myself to change various aspects of the game (things like the character/stage/collision data). For example, I might have a character class like this: class Character { public: int x, y; // Character's location Character* teammate; } I set up my parser to read in from a file the data structure with syntax similar to C++ Character Sidekick { X = 12 Y = 0 } Character AwesomeDude { X = 10 Y = 50 Teammate = Sidekick } This will

Fastest way to skip lines while parsing files in Ruby?

独自空忆成欢 提交于 2019-12-12 07:51:32
问题 I tried searching for this, but couldn't find much. It seems like something that's probably been asked before (many times?), so I apologize if that's the case. I was wondering what the fastest way to parse certain parts of a file in Ruby would be. For example, suppose I know the information I want for a particular function is between lines 500 and 600 of, say, a 1000 line file. (obviously this kind of question is geared toward much large files, I'm just using those smaller numbers for the

calculating average of values from a CSV file in C

﹥>﹥吖頭↗ 提交于 2019-12-12 06:53:26
问题 I am writing a code in which I am reading from a CSV text file which is given as an argument in the command line. I have to calculate the averages of the experiments of the given file: for example, if the file is Bob's experiment,12,33,55,8 Mary's experiment,99,21,12,0 I have to print out Bob's experiment (average of numbers) Mary's experiment(average of numbers) Here is my code: #include<stdio.h> #include<stdlib.h> #include<stdlib.h> #include<string.h> int main (int argc, char *argv[]){ FILE

Parsing text file separated by comma

一世执手 提交于 2019-12-12 03:29:23
问题 I am developing an application to read a text file and plot a graph. the text file will be something like #Pattern Name Item1, Item2, Item3, gx1, gy1, gz1 115, 80, 64, 30.752, 27.587, 15.806 195, 151, 130, 108.983, 102.517, 66.353 94, 123, 156, 43.217, 50.874, 93.700 88, 108, 65, 26.158, 37.980, 17.288 130, 129, 177, 68.096, 66.289, 127.182 100, 190, 171, 71.604, 119.764, 122.349 ......................................... ........................................ #Pattern Name2 Item1, Item2,

How to read in python the KTX file format used in the book Superbible OpenGL? part 2 of an example

主宰稳场 提交于 2019-12-11 15:08:18
问题 In part 1 we read the SBM file format successfully, this is part 2 on how to read the KTX file format. Update: June 25, 2019, the below code to read the ktx file format does work. The file is ktxloader.py Though the code is still a work in progress. Any comments on it would be appreciated. The code below is a working example to create and modify ktxloader.py Files required: pattern1.ktx is our KTX file, to be read this program torus_nrms_tc.sbm is our SBM file solved in part1 in a folder

grep -A <num> until a string

雨燕双飞 提交于 2019-12-11 08:06:55
问题 assuming that we have a file containing the following: chapter 1 blah blah blah num blah num num blah num blah ... blah num chapter 2 blah blah and we want to grep this file so we take the lines from chapter 1 blah blah to blah num (the line before the next chapter). The only things we know are the stating string chapter 1 blah blah somewhere after that there is another line starting with chapter a dummy way to do this is grep -A <num> -i "chapter 1" <file> with large enough <num> so the