|
General Discussion General discussion about SageTV and related companies, products, and technologies. |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
A little Python Help....
I am having a brain fart... this should be so easy but....
I have a text file that I would like to add an incremental number to the end of each instance for example of the word "STUDENT: sudent.txt blah blah blah STUDENT001 next Instance STUDENT002 etc and so on.
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. Last edited by nyplayer; 04-28-2023 at 11:35 AM. |
#2
|
|||
|
|||
Try using ChatGPT from the Bing search engine. I asked it "how do you loop through numbers 1 to 10 in python and add the number to the word "student""
Code:
You can loop through numbers 1 to 10 in Python using a for loop and add the number to the word “student” by typecasting the number into a string using typecasting and then concatenating using the ‘+’ operator. Here’s an example: for i in range(1, 11): text = "student " + str(i) print(text) This will output: student 1 student 2 student 3 student 4 student 5 student 6 student 7 student 8 student 9 student 10 I hope this helps! Let me know if you have any other questions.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server |
#3
|
|||
|
|||
Quote:
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. Last edited by nyplayer; 04-29-2023 at 10:25 AM. |
#4
|
|||
|
|||
Not sure exactly what you are asking for, does this work:
Code:
You can loop through a text file called “student.txt” and replace each instance of “STUDENT” with “STUDENT1” where the number is incremented by using a for loop and the replace() function1. Here’s an example: with open('student.txt', 'r') as f: lines = f.readlines() with open('student.txt', 'w') as f: for i, line in enumerate(lines): line = line.replace('STUDENT', f'STUDENT{i+1}') f.write(line) This will replace each instance of “STUDENT” with “STUDENT1”, “STUDENT2”, etc.
__________________
New Server - Sage9 on unRAID 2xHD-PVR, HDHR for OTA Old Server - Sage7 on Win7Pro-i660CPU with 4.6TB, HD-PVR, HDHR OTA, HVR-1850 OTA Clients - 2xHD-300, 8xHD-200 Extenders, Client+2xPlaceshifter and a WHS which acts as a backup Sage server |
#5
|
|||
|
|||
Quote:
It worked Thank you
__________________
Channels DVR UBUNTU Server 2 Primes 3 Connects TVE SageTV Docker with input from Channels DVR XMLTV and M3U VIA Opendct. Last edited by nyplayer; 04-29-2023 at 10:53 AM. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need Python help .... | nyplayer | General Discussion | 19 | 02-22-2022 12:05 AM |