[Tutor] Using 'with open' statementfor reading a file two lines at a time

Mats Wichmann mats at wichmann.us
Thu Nov 26 20:23:35 EST 2020


On 11/26/20 6:00 PM, Alan Gauld via Tutor wrote:
> On 27/11/2020 00:37, Ken Green wrote:
> 
>> I am using 'with open' statement to read a file two lines at a time and
>> then combining them together to print the results into another file.
> 
> Please don't just describe your code and think we can guess
> what you've done.
> 
> Post the actual code and any actual error messages in full.
> 
> There must be at least half a dozen ways to do what you describe.
> We can't fix what we can't see.
> 
>> How can I continue reading the third and fourth lines and so forth on
>> until the end of the file?
> 
> You need to use a loop, either a 'while' or 'for'
> But without seeing what you've done so far I can't say more than that.
> 
>> (2020-11-5) as an interface. I used to use Geany but discovered the
>> latest version doesn't work in Ubuntu 20.04 and it only applicable for
>> Windows and Apple and there is no Linux version according to its website.
> 
> I'm pretty sure there is a Linux version, in fact I just checked
> and v1.37 has just been released on Linux as well as Windoze and
> MacOS.
> v1.36 is available in the software tool for my Linux Mint 20 which
> is based on Ubuntu 20 so you should definitely be able to get
> it working.

I checked in Fedora, and it remains a supported package there. Perhaps - 
we can only guess - what they meant is that they don't make Linux 
packages, because the distributions still make Linux packages.  And, 
looking in an Ubuntu VM - geany is available there as a package too.

> But if not there are a zillion other code editors out there that
> will do just fine!

Take a look here for some (it's certainly not a complete list!)

https://wiki.python.org/moin/IntegratedDevelopmentEnvironments

I've used several of these and most of the ones I've used are quite good 
(Visual Studio Code is quite popular at the moment, technically it's not 
an IDE but extensions basically make it so, PyCharm is excellent and the 
community version is not very limited, WingIDE is the old standby that 
still has a good no-cost version, and Thonny is a nice free lightweight 
one. Amongst ones not on the page the Atom editor also does a fine job 
on Python).


More information about the Tutor mailing list