text-files

How to convert a .txt to .xml in python

How to convert a .txt to .xml in python Question: So the current problem I’m facing would be in converting a text file into a xml file. The text file would be in this format. Serial Number: Operator ID: test Time: 00:03:47 Test Step 2 TP1: 17.25 TP2: 2.46 Serial Number: Operator ID: test Time: …

Total answers: 2

Open textfile and get the data behind the colon in Python

Open textfile and get the data behind the colon in Python Question: This is my Example list for you which is stored in a textfile: DEVICE: Test HW-RELEASE: Test SERIAL-NUMBER: Test MAC-ADDRESS: Test IP-ADDRESS: Test IP-NETMASK: Test INTRANET-ADDRESS: Test INTRANETMASK: Test VERSION: Test NAME: Test CONFIG-STATUS: Test FIRMWARE-STATUS: Test HW-MASK: Test FEATUREWORD: Test REGISTERED-WORD: Test …

Total answers: 4

Pickle module in Python and text files

Pickle module in Python and text files Question: I have recently asked a question and received an answer that I must ‘pickle’ my code. As a beginner, I have no idea how to do that. This was my code: users = [] users.append([username, password]) usersFile = open("users.txt","w+") for users in users: usersFile.write("%s" % users) usersFile.close() …

Total answers: 2

numpy.savetxt- Save one column as int and the rest as floats?

numpy.savetxt- Save one column as int and the rest as floats? Question: The Problem So I have a 2D array (151 rows, 52 columns) I’d like to save as a text file using np.savetxt. However, I want the first column’s numbers to save as integers (1950, 1951, etc) while the rest of the data saves …

Total answers: 4

Copying from one text file to another using Python

Copying from one text file to another using Python Question: I would like to copy certain lines of text from one text file to another. In my current script when I search for a string it copies everything afterwards, how can I copy just a certain part of the text? E.g. only copy lines when …

Total answers: 7

Performance effect of using print statements in Python script

Performance effect of using print statements in Python script Question: 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 …

Total answers: 2

Python Multiple users append to the same file at the same time

Python Multiple users append to the same file at the same time Question: I’m working on a python script that will be accessed via the web, so there will be multiple users trying to append to the same file at the same time. My worry is that this might cause a race condition where if …

Total answers: 4

How to overwrite a folder if it already exists when creating it with makedirs?

How to overwrite a folder if it already exists when creating it with makedirs? Question: The following code allows me to create a directory if it does not already exist. dir = ‘path_to_my_folder’ if not os.path.exists(dir): os.makedirs(dir) The folder will be used by a program to write text files into that folder. But I want …

Total answers: 6

How do you dynamically identify unknown delimiters in a data file?

How do you dynamically identify unknown delimiters in a data file? Question: I have three input data files. Each uses a different delimiter for the data contained therein. Data file one looks like this: apples | bananas | oranges | grapes data file two looks like this: quarter, dime, nickel, penny data file three looks …

Total answers: 5

Best way to retrieve variable values from a text file?

Best way to retrieve variable values from a text file? Question: 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 …

Total answers: 11