Python Forum
Ignore first few letters of a line when reading file.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ignore first few letters of a line when reading file.
#16
@BitPythoner, in python you don't need the position, nor need to convert to list - you can iterate over str:
>>> spam = 'name = John'
>>> for char in spam:
...     print(char)
... 
n
a
m
e
 
=
 
J
o
h
n
>>> for idx, char in enumerate(spam):
...     print(f'position:{idx}, char:{char}')
... 
position:0, char:n
position:1, char:a
position:2, char:m
position:3, char:e
position:4, char: 
position:5, char:=
position:6, char: 
position:7, char:J
position:8, char:o
position:9, char:h
position:10, char:n
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Ignore first few letters of a line when reading file. - by buran - May-30-2020, 04:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading and storing a line of output from pexpect child eagerissac 1 4,245 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  Copy Paste excel files based on the first letters of the file name Viento 2 437 Feb-07-2024, 12:24 PM
Last Post: Viento
Sad problems with reading csv file. MassiJames 3 632 Nov-16-2023, 03:41 PM
Last Post: snippsat
  Reading in of line not working? garynewport 2 837 Sep-19-2023, 02:22 PM
Last Post: snippsat
  Reading a file name fron a folder on my desktop Fiona 4 916 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,102 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,564 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  Getting last line of each line occurrence in a file tester_V 1 867 Jan-31-2023, 09:29 PM
Last Post: deanhystad
  Reading a file JonWayn 3 1,095 Dec-30-2022, 10:18 AM
Last Post: ibreeden
  Reading Specific Rows In a CSV File finndude 3 989 Dec-13-2022, 03:19 PM
Last Post: finndude

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020