1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

*** SIMPLE Python Help ***

Discussion in 'Black Hat SEO' started by balabala1221, Feb 3, 2013.

  1. balabala1221

    balabala1221 Junior Member

    Joined:
    Oct 5, 2012
    Messages:
    188
    Likes Received:
    9
    Occupation:
    Engineer
    Location:
    NYC
    hi im running a script in python that strips each line one at a time from my .txt file until each line is stripped it looks like this:

    while True:
    a = f.readline().strip()

    my question is if i want it to strip only lines 100-200 how would i do that?

    thanks in advance
     
  2. schwarpitz

    schwarpitz Newbie

    Joined:
    Oct 27, 2008
    Messages:
    24
    Likes Received:
    3
    Location:
    Morocco
    for line in f.readlines()[99:200]:
    stripped_line=line.strip()
     
    • Thanks Thanks x 1
  3. balabala1221

    balabala1221 Junior Member

    Joined:
    Oct 5, 2012
    Messages:
    188
    Likes Received:
    9
    Occupation:
    Engineer
    Location:
    NYC
    i tried the following and it's giving me an error:

    while True:
    for line in f.readlines()[99:200]:
    nbr = f.readline().strip()
    bla
    bla
    bla
    f.close()

    any help? thanks
     
  4. sirgold

    sirgold Supreme Member

    Joined:
    Jun 25, 2010
    Messages:
    1,260
    Likes Received:
    645
    Occupation:
    Busy proving the Pareto principle right
    Location:
    A hot one
    • Thanks Thanks x 1
  5. balabala1221

    balabala1221 Junior Member

    Joined:
    Oct 5, 2012
    Messages:
    188
    Likes Received:
    9
    Occupation:
    Engineer
    Location:
    NYC
    still stuck man lol suck at python
     
  6. balabala1221

    balabala1221 Junior Member

    Joined:
    Oct 5, 2012
    Messages:
    188
    Likes Received:
    9
    Occupation:
    Engineer
    Location:
    NYC
    every thing i read just strips all the lines from 100-200 and pastes them all at once. i want one line to be stripped at a time, run it thru my loop, then go to the next line is completed

    any help would be appreciated lil it's driving me crazy idk how u programmers do it
     
  7. QuietZorg

    QuietZorg Regular Member

    Joined:
    Feb 7, 2010
    Messages:
    259
    Likes Received:
    158
    Ok, I don't have python installed on this machine, so tomorrow I can help more, but for now:

    -Try debugging your code. Pyscriptor is a great, free Python interpreter, and you can step through the code, statement by statement, and see exactly what's happening by checking the values of all the variables of interest.

    -Make sure your indentation is correct. It's safer to use four spaces instead of tab.

    -
    while True:
    for line in f.readlines()[99:200]:
    nbr = f.readline().strip()
    bla
    f.close()

    Why do you have a while True there at the beginning? What's that achieving?

    Like I said, I don't have Python installed here, but if I was you I'd try something like (excuse syntax mistakes, you get the idea though)

    fid = fopen('yourfile.txt')
    fileContent = fid.readlines()
    for i = 99:200
    ^^^^tempString = fileContent
    ^^^^do yo' thang tempString
    fclose(fid)


    ^^^^ are spaces.
    Try something like that. If you still have trouble, and no one posts a proper answer by this time tomorrow, I will.
     
    • Thanks Thanks x 1
    Last edited: Feb 3, 2013
  8. balabala1221

    balabala1221 Junior Member

    Joined:
    Oct 5, 2012
    Messages:
    188
    Likes Received:
    9
    Occupation:
    Engineer
    Location:
    NYC
    Thanks man really helpful, I have a while true because its a loop. Basically I use sikuli and what I want to do is, for a custom range on the text file, sikuli to strip a line, run the command then go to the next line, run the command etc all the way til the last line in the range