x404.co.uk http://www.x404.co.uk/forum/ |
|
Python http://www.x404.co.uk/forum/viewtopic.php?f=4&t=10185 |
Page 1 of 1 |
Author: | Angelic [ Wed Aug 25, 2010 12:03 pm ] | |||||||||
Post subject: | Python | |||||||||
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 |
Author: | EddArmitage [ Wed Aug 25, 2010 12:37 pm ] | |||||||||
Post subject: | Re: Python | |||||||||
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:
|
Author: | Angelic [ Wed Aug 25, 2010 1:57 pm ] | ||||||||||||||||||
Post subject: | Re: Python | ||||||||||||||||||
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:
How do you reckon I would get it to print a certain line? |
Author: | EddArmitage [ Wed Aug 25, 2010 2:14 pm ] | |||||||||
Post subject: | Re: Python | |||||||||
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:
|
Author: | Angelic [ Wed Aug 25, 2010 2:41 pm ] |
Post subject: | Re: Python |
Well that hasn't worked on its own, but I shall certainly read around it and report back with my findings! |
Author: | EddArmitage [ Wed Aug 25, 2010 2:45 pm ] |
Post subject: | Re: Python |
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! |
Author: | Angelic [ Thu Aug 26, 2010 12:12 pm ] |
Post subject: | Re: Python |
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... |
Author: | EddArmitage [ Thu Aug 26, 2010 12:17 pm ] | |||||||||
Post subject: | Re: Python | |||||||||
Sure. It'd be good to revive my scripting skills a bit! |
Author: | Angelic [ Thu Aug 26, 2010 3:45 pm ] | |||||||||||||||||||||||||||||||||||||||||||||
Post subject: | Re: Python | |||||||||||||||||||||||||||||||||||||||||||||
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 >.< |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |