text-files

python opens text file with a space between every character

百般思念 提交于 2019-12-05 10:32:58
问题 Whenever I try to open a .csv file with the python command fread = open('input.csv', 'r') it always opens the file with spaces between every single character. I'm guessing it's something wrong with the text file because I can open other text files with the same command and they are loaded correctly. Does anyone know why a text file would load like this in python? Thanks. Update Ok, I got it with the help of Jarret Hardie's post this is the code that I used to convert the file to ascii fread =

C# Removing separator characters from quoted strings

喜你入骨 提交于 2019-12-05 10:27:20
I'm writing a program that has to remove separator characters from quoted strings in text files. For example: "Hello, my name is world" Has to be: "Hello my name is world" This sounds quite easy at first (I thought it would be), but you need to detect when the quote starts, when the quote ends, then search that specific string for separator characters. How? I've experimented with some Regexs but I just keep getting myself confused! Any ideas? Even just something to get the ball rolling, I'm just completely stumped. string pattern = "\"([^\"]+)\""; value = Regex.Match(textToSearch, pattern)

Python open(“x”, “r”) function, how do I know or control which encoding the file is supposed to have?

北慕城南 提交于 2019-12-05 09:10:29
If a python script uses the open("filename", "r") function to open, and subsequently read, the contents of a text file, how can I tell which encoding this file is supposed to have? Note that since I'm executing this script from my own program, if there is any way to control this through environment variables, then that is good enough for me. This is Python 2.7 by the way. The code in question comes from Mercurial, it can be given a list of files to, say, add to the repository, through a file on disk, instead of passing them on the command line. So basically, instead of this: hg add A B C I can

Using OleDbConnection to Read Tab-Separated File

时光毁灭记忆、已成空白 提交于 2019-12-05 08:33:43
My tab-delimited file is something like this: ISO ISO3 ISO-Numeric AD AND 20 I've been trying the following code with no luck. OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= |DataDirectory|;Extended Properties='text;HDR=Yes;FMT=TabDelimited'"); OleDbCommand cmd = new OleDbCommand(@"SELECT * FROM countryInfo.txt", cn); OleDbDataAdapter da = new OleDbDataAdapter(cmd); cn.Open(); DataTable dt = new DataTable(); da.Fill(dt); Here's a screenshot of the Dataset Visualizer. Its obviously not the output i'm after. Any suggestions? Here's my Schema.ini file.

The correct way to populate a JComboBox?

馋奶兔 提交于 2019-12-05 08:27:20
I am currently building an application in Java on Eclipse as a self help guide to programming fundamentals and basic java programming, this is purely educational and for the sole purpose of being able to reference topics easily and practice my programming as I learn them by programming them into this tutorial application. The content of the application will expand as time goes on and as I learn more components of programming. So my first question comes down to correct form. I am using a drop down box ( JComboBox ) so as to select specific topics from within the GUI. I would like to populate

Best way for read and write a text file

廉价感情. 提交于 2019-12-05 08:24:45
I am using the latest version of Lazarus IDE and I have a Memo1 on my TForm1. I have to load a text file in Memo1 and then edit every line of the Memo (I use Memo1.Lines.Strings[i] := ... ). At the end I must save the edited memo at a particular path. Question : I am looking for the faster way between: Load the whole text inside the memo, edit its content and save into a new file (load all -> edit all -> write all) Do a while loop (until the end of my *.txt file) that reads the file line by line, edit the content and save it in the new file. (load line -> edit -> write | load -> edit -> write

How to generate a random named text file in C#?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 07:50:00
I have to make a loop to generate a 5 randomly-picked-letter string, and then create a text file under that name, lets say in C:// , how will I do that? Both the generating name and creating a file in the directory. I think I have to pick 5 random numbers from the ascii codes add them to an array and then convert them to the character equivalents to be able to use it as a name. Idk how I'll convert them to character and make up a string with them, could you help me? If you want to create the file names youself, put the characters that you want to use in a string and pick from that: // selected

Read two textfile line by line simultaneously -java

╄→гoц情女王★ 提交于 2019-12-05 04:19:04
I have 2 textfiles in two different languages and they are aligned line by line. I.e. the first line in the textfile1 should be equals to the first line in textfile2, and so on and so forth. Is there a way to read both file line-by-line simultaneously? Below is a sample of how the files should look like, imagine the number of lines per file is around 1,000,000. textfile1: This is a the first line in English This is a the 2nd line in English This is a the third line in English textfile2: C'est la première ligne en Français C'est la deuxième ligne en Français C'est la troisième ligne en Français

Fastest way to load data from text file then store it into database

白昼怎懂夜的黑 提交于 2019-12-05 04:11:01
问题 I have problem. I'm developing a project but I'm stuck in this part: I want to load a data from text file and store it into database access the things is the data inside each text file about 12.000 lines of data and each text file it takes about 10 minute to process it.. NOTE : before store the data, I separate each line of data from text file and put it into string then I check whether the data is already inside database or not. if inside the database I update it. If not then I use insert

Creating a new .txt file with date in front, C#

烂漫一生 提交于 2019-12-05 01:23:13
问题 I am trying to get the following: [today's date]___[textfilename].txt from the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication29 { class Program { static void Main(string[] args) { WriteToFile(); } static void WriteToFile() { StreamWriter sw; sw = File.CreateText("c:\\testtext.txt"); sw.WriteLine("this is just a test"); sw.Close(); Console.WriteLine("File created successfully"); } } } I tried