Linked Questions

6 votes
2 answers
1k views

I'm wondering if there is a construction in Python 3 that allows me to open two (or more) files on the same with context. What I'm looking for is something like this: from pathlib import Path file1 ...
accdias's user avatar
  • 5,352
0 votes
1 answer
2k views

Is it possible to use the with context manager syntax with more than one object in Python? For example, something like: with open("file1.txt") as file1, open("file2.txt") as file2: ...
user2138149's user avatar
  • 18.7k
2 votes
0 answers
2k views

Possible Duplicate: Python: open multiple files using “with open”? Does, With open() not works with python 2.6 I have seen other answers to help me with this. But I can't seem to get any of the ...
junyi00's user avatar
  • 792
-1 votes
2 answers
772 views

Hi i was going to open multiple txt files in a directory. But i get error message of File "testTopic.py", line 9, in <module> with open(path +i, 'r') as f: IOError: [Errno 2] No ...
xxxSL's user avatar
  • 121
0 votes
0 answers
93 views

I would like to accept a certain number (limited to - say, 3) to evaluate a condition within the a with statement. I did find it's possible to do something like this. Can I do something similar to the ...
skrowten_hermit's user avatar
655 votes
8 answers
252k views

Is it possible to declare more than one variable using a with statement in Python? Something like: from __future__ import with_statement with open("out.txt","wt"), open("in.txt") as file_out, ...
pufferfish's user avatar
  • 17.6k
113 votes
7 answers
114k views

I have a Python function that writes an output file to disk. I want to write a unit test for it using Python's unittest module. How should I assert equality of files? I would like to get an error if ...
jan's user avatar
  • 1,643
7 votes
2 answers
29k views

I'm new to python. I'm want to open multiple files in Python. I'm can open each of them with open() function. I'm not sure about formatting. with open("/test/filename.css", "r") as f: s = f....
user avatar
3 votes
2 answers
5k views

I have a folder with multiple couple of files: a.txt a.json b.txt b.json and so on: Using a for loop i want to open a couple of file (a.txt and a.json) concurrently. Is there a way to do ...
CosimoCD's user avatar
  • 3,840
2 votes
1 answer
4k views

I've been asked by a colleague to convert 6 huge files from the "Yelp Dataset Challenge" from somewhat "flat," regular JSON into CSV (he thinks they look like fun teaching data). I thought I could ...
k..'s user avatar
  • 401
0 votes
2 answers
2k views

I have a list of numbers and need to put them all into a text file on their own line. I can't figure out how to call to each item and print them. I only know how to write strings into a text file. ...
Rob Blaze's user avatar
2 votes
2 answers
2k views

I would like to combine columns of various csv files into one csv file, with a new heading, concatenated horizontally. I want to only select certain columns,chosen by heading. There are different ...
moink's user avatar
  • 898
1 vote
1 answer
2k views

I'm trying to open 2 files, one of which has content and one which is empty. For the lines that are not headers, I read each line and process it before writing the processed line to the empty file, ...
bard's user avatar
  • 3,112
0 votes
1 answer
3k views

Update It's throwing the error with a direct call now, and in the relations docs. I got rid of write_el() altogether and just do this: ... if el["doc_type"] == "node": with ...
Kaleb Coberly's user avatar
1 vote
2 answers
255 views

I want to read in from a file, "ee_pinkH1.xpk" This is what my ee_pinkH1.xpk file looks like: label dataset sw sf 1H 1H_2 NOESY_F1eF2e.nv 4807.69238281 4803.07373047 600.402832031 600.402832031 1H.L ...
user8358234's user avatar

15 30 50 per page