text-files

Best way to retrieve variable values from a text file - Python - Json

冷暖自知 提交于 2019-11-27 17:13:16
Referring on this question , I have a similar -but not the same- problem.. On my way, I'll have some text file, structured like: var_a: 'home' var_b: 'car' var_c: 15.5 And I need that python read the file and then create a variable named var_a with value 'home', and so on. Example: #python stuff over here getVarFromFile(filename) #this is the function that im looking for print var_b #output: car, as string print var_c #output 15.5, as number. Is this possible, I mean, even keep the var type? Notice that I have the full freedom to the text file structure, I can use the format I like if the one

java replace specific string in textfile

馋奶兔 提交于 2019-11-27 16:17:03
I've got a text file called log.txt It's got the following data 1,,Mon May 05 00:05:45 WST 2014,textFiles/a.txt,images/download.jpg 2,,Mon May 05 00:05:45 WST 2014,textFiles/a.txt,images/download.jpg the numbers before the first comma are indexes that specify each item. what I want to do is read the file then replace one part of the string(e.g. textFiles/a.txt) in a given line with another value(e.g. something/bob.txt). this is what i have so far File log= new File("log.txt"); String search = "1,,Mon May 05 00:05:45 WST 2014,textFiles/a.txt,images/download.jpg; //file reading FileReader fr =

objective C: write in a csv (txt) string contained in some textfield

佐手、 提交于 2019-11-27 15:57:32
In my project I have a view where I write words in some textfield, when I press a button these string must be stored in a csv file as this example: (example with 5 textfield) firststring#secondstring#thirdstring#fourthstring#fifthstring; this is an example of the result that I want. How can I do? Edited to add: code for the string NSMutableString *csvString = [NSMutableString stringWithString:textfield1.text]; [csvString appendString:@"#"]; [csvString appendString:textfield2.text]; [csvString appendString:@"#"]; [csvString appendString:dtextfield3.text]; [csvString appendString:@"#"];

Export a C# DataSet to a text file

混江龙づ霸主 提交于 2019-11-27 15:52:58
问题 There are a lot of examples online of how to fill a DataSet from a text file but I want to do the reverse. The only thing I've been able to find is this but it seems... incomplete? I want it to be in a readable format, not just comma delimited, so non-equal spacing between columns on each row if that makes sense. Here is an example of what I mean: Column1 Column2 Column3 Some info Some more info Even more info Some stuff here Some more stuff Even more stuff Bits and bobs Note: I only have one

Performance effect of using print statements in Python script

一个人想着一个人 提交于 2019-11-27 15:38:27
问题 I have a Python script that process a huge text file (with around 4 millon lines) and writes the data into two separate files. I have added a print statement, which outputs a string for every line for debugging. I want to know how bad it could be from the performance perspective? If it is going to very bad, I can remove the debugging line. Edit It turns out that having a print statement for every line in a file with 4 million lines is increasing the time way too much. 回答1: Tried doing it in a

Easiest way to add a text to the beginning of another text file in Command Line (Windows)

别来无恙 提交于 2019-11-27 15:35:45
问题 What is the easiest way to add a text to the beginning of another text file in Command Line (Windows)? 回答1: echo "my line" > newFile.txt type myOriginalFile.txt >> newFile.txt type newFile.txt > myOriginalFile.txt Untested. Double >> means 'append' 回答2: Another variation on the theme. (echo New Line 1) >file.txt.new type file.txt >>file.txt.new move /y file.txt.new file.txt Advantages over other posted answers: minimal number of steps no temp file left over parentheses prevents unwanted

Load .txt file using JQuery or Ajax

北城以北 提交于 2019-11-27 15:32:52
How can I fix the script below so that it will work EVERY TIME! Sometimes it works and sometimes it doesn't. Pro JQuery explains what causes this, but it doesn't talk about how to fix it. I am almost positive it has to do with the ajax ready state but I have no clue how to write it. The web shows about 99 different ways to write ajax and JQuery, its a bit overwhelming. My goal is to create an HTML shell that can be filled with text from server based text files. For example: Let's say there is a text file on the server named AG and its contents is PF: PF-01, PF-02, PF-03, etc.. I want to pull

How do I sort records in a text file using Java?

為{幸葍}努か 提交于 2019-11-27 15:17:26
Some amendment of the data in txt file. I have tried the suggested code but Im not successfully write it again in the txt file with this format.I've tried the collection.sort but it write the data in long line. My txt file contain these data: Monday Jessica Run 20mins Alba Walk 20mins Amy Jogging 40mins Bobby Run 10mins Tuesday Mess Run 20mins Alba Walk 20mins Christy Jogging 40mins Bobby Run 10mins How can I sort those data in ascending order and store it again in txt file after sorting? Monday Alba Walk 20mins Amy Jogging 40mins Bobby Run 10mins Jessica Run 20mins Tuesday Alba Walk 20mins

Preserving leading white space while reading>>writing a file line by line in bash

孤街浪徒 提交于 2019-11-27 15:14:51
I am trying to loop through a directory of text files and combine them into one document. This works great, but the text files contain code snippets, and all of my formatting is getting collapsed to the left. All leading whitespace on a line is stripped. #!/bin/sh OUTPUT="../best_practices.textile" FILES="../best-practices/*.textile" for f in "$FILES" do echo "Processing $f file..." echo "">$OUTPUT cat $f | while read line; do echo "$line">>$OUTPUT done echo >>$OUTPUT echo >>$OUTPUT done I am admittedly a bash noob, but after searching high and low I couldn't find a proper solution. Apparently

Read txt file with multi-threaded in python

梦想与她 提交于 2019-11-27 14:36:14
问题 I'm trying to read a file in python (scan it lines and look for terms) and write the results- let say, counters for each term. I need to do that for a big amount of files (more than 3000). Is it possible to do that multi threaded? If yes, how? So, the scenario is like this: Read each file and scan its lines Write counters to same output file for all the files I've read. Second question is, does it improve the speed of read/write. Hope it is clear enough. Thanks, Ron. 回答1: I agree with @aix,