View unanswered posts | View active topics
It is currently Sat Jul 05, 2025 9:00 pm
|
Page 1 of 1
|
[ 9 posts ] |
|
Author |
Message |
Angelic
Doesn't have much of a life
Joined: Thu Apr 23, 2009 7:16 pm Posts: 704 Location: Leeds, UK
|
Hey guys, Muddling through some Python, wondered if anyone here could help a little bit? Basically what i'm trying to do is open one .txt file and input the values into a list in Python. Then i'm opening another .txt file, and inputting all those values into another list in Python (but one that preserves the table structure). What I want to do is take a number from the first text file and use it to print that number line from the second. For instance: Text file contains just the number "4". Text file 2 contains rows which read: 0, MON, 0800, 1, MON, 0830, 2, MON, 0900, 3, MON, 0930, 4, MON, 1000, [etc] And all I want to happen is that 5th row to be printed... Anyone know how yet? Here's what i've got so far: but, obviously, it doesn't work! I just want SOMETHING to be returned >.< But i've been up all night trying to do this and don't seem to have progressed.. I mean I started at 2pm yesterday and would like something working before the 24 hour mark! Lol
|
Wed Aug 25, 2010 12:03 pm |
|
 |
EddArmitage
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 9:40 pm Posts: 5288 Location: ln -s /London ~
|
The uni VPN is down today, so I can't get at my old python stuff, but looking at this, and going a bit from memory, I guess you could try something like:
|
Wed Aug 25, 2010 12:37 pm |
|
 |
Angelic
Doesn't have much of a life
Joined: Thu Apr 23, 2009 7:16 pm Posts: 704 Location: Leeds, UK
|
You've definitely pointed me in the right direction, I now have this: This brings me a list of all the rows, in the following format:  |  |  |  | Code: ['0,0800,MON'] ['1,0830,MON'] ['2,0900,MON'] ['3,0930,MON'] ['4,1000,MON']
|  |  |  |  |
How do you reckon I would get it to print a certain line?
|
Wed Aug 25, 2010 1:57 pm |
|
 |
EddArmitage
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 9:40 pm Posts: 5288 Location: ln -s /London ~
|
Could you not assign a value to a variable index? I presume you then want to loop through the first file (containing indices) and print those rows of the second file? Could you not do something like:
|
Wed Aug 25, 2010 2:14 pm |
|
 |
Angelic
Doesn't have much of a life
Joined: Thu Apr 23, 2009 7:16 pm Posts: 704 Location: Leeds, UK
|
Well that hasn't worked on its own, but I shall certainly read around it and report back with my findings!
|
Wed Aug 25, 2010 2:41 pm |
|
 |
EddArmitage
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 9:40 pm Posts: 5288 Location: ln -s /London ~
|
If I get up to campus tonight I'll have a look for you. At least then I'll actually have a python interpretter, and not be coding in C++ at the same time!
|
Wed Aug 25, 2010 2:45 pm |
|
 |
Angelic
Doesn't have much of a life
Joined: Thu Apr 23, 2009 7:16 pm Posts: 704 Location: Leeds, UK
|
Well i've made huge progress! Not exactly the most gripping of subjects, but if anyone wants to see how I did it I can post what i've done...
|
Thu Aug 26, 2010 12:12 pm |
|
 |
EddArmitage
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 9:40 pm Posts: 5288 Location: ln -s /London ~
|
Sure. It'd be good to revive my scripting skills a bit!
|
Thu Aug 26, 2010 12:17 pm |
|
 |
Angelic
Doesn't have much of a life
Joined: Thu Apr 23, 2009 7:16 pm Posts: 704 Location: Leeds, UK
|
Well this is what I have so far... The next bit is what i'm going to have trouble with: How would I go about this? What is basically happening is i'm looking down all the lines in the list "reference" (which was imported right at the beginning) and for each line in "scheduled_periods" I need to output the matching data from. Put simply (and not ridiculously, like my last paragraph): Reference contains the data what we've seen before: Scheduled_Periods contains the data: And I would very much like to be printed to screen: Obviously it'll be running on a much larger scale (numbers going up to 149) and have about 10-30 results to sift through but i'm not looking for anything that's particularly CPU-friendly, just need it to work >.<
|
Thu Aug 26, 2010 3:45 pm |
|
|
|
Page 1 of 1
|
[ 9 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum
|
|