-5

When i make error? Don't see errors. Please, help me.

datafile = file('c:\\Users\\username\\Desktop\\test.txt')
    for line in datafile:
        if '5256' in line:
            GLOBACCESS[jid]=100
            reply('private', source, u'You license is valid!')
        else:   
            reply('private', source, u'Incorrect password/jid')
user2491643
  • 1
  • 1
  • 1
  • you're mixing tabs and spaces. – roippi Jan 20 '14 at 21:11
  • Why is your `for line in datafile:` line indented? – inspectorG4dget Jan 20 '14 at 21:11
  • Mixing tabs and spaces won't trigger an error in Python 2.x, but it's bad programming practice regardless. Your error lies in the indentation of the for loop. – jayelm Jan 20 '14 at 21:13
  • Hint: If you're getting a message saying your question has a duplicate title, you might want to take a look at the question it links to. If you look at the sidebar, you'll notice multiple similar questions that you can look at. For example, [this highly rated one](http://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level?rq=1). – thegrinner Jan 20 '14 at 21:15
  • @jmu303: that is incorrect. Mixing tabs and spaces does raise errors in python2.x... depending on how you mix them – inspectorG4dget Jan 20 '14 at 21:16
  • @inspectorG4dget really? I'm sure you know more than me, I'm just inferring from [PEP 8](http://www.python.org/dev/peps/pep-0008/#tabs-or-spaces) – jayelm Jan 20 '14 at 21:17
  • @jmu303: I've gotten those errors before – inspectorG4dget Jan 20 '14 at 21:17
  • @inspectorG4dget "When invoking the Python 2 command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!" My assumption was that if these options weren't chosen, Python wouldn't throw errors? – jayelm Jan 20 '14 at 21:19
  • Python2 interprets tabs as 8 spaces without complaint as long as that works indentation-wise – mhlester Jan 20 '14 at 21:23
  • @jmu303: Fair point. That makes sense – inspectorG4dget Jan 20 '14 at 21:30
  • BTW, according to the documentation you shouldn't use `file` to open a file. Use `open` instead. – Matthias Jan 21 '14 at 08:05

2 Answers2

2

Lines 2 and 3 are using spaces while everything else is using tabs. You always need to use the same, and should choose spaces per pep 8

Line 2 shouldn't be indented at all, with spaces or with tabs

mhlester
  • 22,781
  • 10
  • 52
  • 75
0

for loop shouldn't be indented.

datafile = file('c:\\Users\\username\\Desktop\\test.txt')
for line in datafile:
     if '5256' in line:
        GLOBACCESS[jid]=100
        reply('private', source, u'You license is valid!')
     else:   
        reply('private', source, u'Incorrect password/jid')
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241
jayelm
  • 7,236
  • 5
  • 43
  • 61