Questions tagged [file-handling]

file-handling is an abstraction of common actions such as creating, opening, closing, reading, updating, writing, comparing and deleting files

2915 questions
0
votes
0 answers

File handler as an argument for a function in cython

What should be the variable type of a _io.TextIOWrapper object as argument for a function in Cython? e.g. f = open("myfile.txt","r") cpdef int myFunction(f): ... return 0 Something like this?: cpdef int myFunction(FILE* f): ... …
aerijman
  • 2,522
  • 1
  • 22
  • 32
0
votes
0 answers

Limit file Size while writing

I am in pursuit to create a CSV file, with size constraints defined by Bytes. For e.g. i need to keep writing to a file, that would contain CSV data, so it doesn't exceed file limit of 5MB. Without any loss of data in the row. Obvious solution would…
s_s_
  • 463
  • 5
  • 20
0
votes
2 answers

Writing to a file from python also adds additional characters to the last line

I have a python file named constants.py with the following contents from pytestLoop.config.testdata_005_connect_for_bank_statements import * xpath_username="//div[text()='"+uname+"']" pswd="//div[@id='password']" # this is the end of the file. I…
Fuze Test
  • 31
  • 6
0
votes
1 answer

Extra curly bracket generated in js.dump

I came across the following problem, the code example below is returning a curly bracket too much every second call: import json as js def switchState(path, type): file = open(path + '/states.txt', 'r+') json = js.loads(file.read()) …
Asel
  • 15
  • 3
0
votes
2 answers

how to open a text file(or any file) located in a folder other than the project folder in java

FileDialog fc=new FileDialog (new Frame(),"Test File Dialog"); fc.setVisible(true); String selectedFile=fc.getFile(); File file = new File(selectedFile); String absolutepath = file.getAbsolutePath(); hi, am trying to get the full file…
StackTrace
  • 9,190
  • 36
  • 114
  • 202
0
votes
0 answers

Update the contents of a file in Python

I am trying to update the contents of the file swimmerpoints.txt. My current code is as follows: def update(): swimmerid = [] name = [] points = [] files = open('swimmerpoints.txt', 'a+') for info in files: info = info.strip() …
Johnny
  • 211
  • 3
  • 15
0
votes
1 answer

How to update the xml file using python and BeautifulSoup

I can see that the values are updating but when I check that in XMl file it shows original values , How can I update original XML file with edits or create a new XML file with edits. Here is what I am doing with open("C:/file/abcd.xml","r") as…
Akash Rathor
  • 109
  • 8
0
votes
4 answers

Populating a dictionary from a text file?

So I have a text file that looks something like this: Monstera Deliciosa 2018-11-03 18:21:26 Tropical/sub-Tropical plant Leathery leaves, mid to dark green Moist and well-draining soil Semi-shade/full shade light requirements Water only when top 2…
Aaron
  • 165
  • 8
0
votes
1 answer

fread is reading garbage in file

I am working on my assignment and faced a problem with fread() in C++. When I modify the name in my file it modifies it perfectly as I want but the problem occurs when I try to read the file after that, it reads the whole file but it does not stop…
user13441695
0
votes
1 answer

Reading and writing file in ISO-8859-1 encoding?

I have file encoded in ISO-8859-1. I'm trying to read it in as a single String, do some regex substitutions on it, and write it back out in the same encoding. However, the resulting file I get always seems to be UTF-8 (according to Notepad++ at…
Michael Hillman
  • 1,217
  • 3
  • 15
  • 24
0
votes
0 answers

Problem with read and write functions in c++

I am facing problem with read and write functions in C++ and C also. When I input 2 or more name and ids in my code it writes it perfectly to the file but when I read the file with fread it show some weird behavior it prints same value of ids as I…
user13441695
0
votes
1 answer

How do I print a particular field from a CSV file in python?

import csv with open('doc.csv','r') as f: file=csv.reader(f) for row in file: if row==['NAME']: print(row) I wanted to print all the names from a csv file in…
0
votes
1 answer

How to change an integer inside a file without coping the file to another

I'm making a program for school where i have to create a function for making exams and another one to get the exam. I did the part to create the exam. Now I'm trying to make the part to get the exam. The problem i have in this part is to store the…
Hi its Me
  • 1
  • 3
0
votes
2 answers

How to make a file non-editable?

I am working on an idea. I need a bit help here, as I don't have in depth knowledge of python modules(I mean I don't know all the python modules). Take a look at the code file = open('Data.txt', 'w') a = input('Enter your name in format F|M|L:…
Ruturaj
  • 3
  • 4
0
votes
2 answers

trying to get an output from a file using the user input value then print the value in python

I'm trying to learn python and I wrote this script, that not shows me the right output.. What am i missing? I have a text file like this: test test1 test2 test3 test4 #test5 test6 #test7 #test8 TASK 1: open file: i got this part *do not print or…
sendoh
  • 13
  • 7