Python newbie probleempje

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

  • axis
  • Registratie: Juni 2000
  • Laatst online: 26-01-2023
Ik ben eens begonnen om een nieuw nagios scriptie te schrijven in Python, want met bash ga ik er maar lastig uit komen. Ik loop echter tegen een vaag probleem aan dat ik niet snap.

Mijn code:

t0_failures = 3
t0_success = 0
if [t0_failures < 1]:
t0_success = 1

print ' "t0_failures" : "{0}"'.format(t0_failures)
print ' "t0_failures type" : "{0}"'.format(type(t0_failures))
print ' "t0_success" : "{0}"'.format(t0_success)
print ' "t0_success type" : "{0}"'.format(type(t0_success))

Geeft de output:

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/angelo/PycharmProjects/untitled/debug.py
"t0_failures" : "3"
"t0_failures type" : "<type 'int'>"
"t0_success" : "1"
"t0_success type" : "<type 'int'>"

Process finished with exit code 0

Wait, what? Ik zou verwachten dat 3 niet kleiner is dan 1, en dat daarom t0_success 0 zou blijven. Maar ben ik nou gekke henkie? Ik kijk vast over een typo heen. 8)7

Two advices for network troubleshooting.. learn to draw diagrams in Visio, and THINK IN LAYERS!


Acties:
  • 0 Henk 'm!

  • CyBeR
  • Registratie: September 2001
  • Niet online

CyBeR

💩

Waarom gebruik je blokhaken, precies? Dat doet niet wat je wilt.

All my posts are provided as-is. They come with NO WARRANTY at all.


Acties:
  • 0 Henk 'm!

  • H!GHGuY
  • Registratie: December 2002
  • Niet online

H!GHGuY

Try and take over the world...

je haakjes, dat moeten () zijn, geen []

Je construeert een list met lengte 1 en die evalueert naar True.

ASSUME makes an ASS out of U and ME


Acties:
  • 0 Henk 'm!

  • axis
  • Registratie: Juni 2000
  • Laatst online: 26-01-2023
Doh!! thnx.. Dat verklaart een boel. Hoe lang kun je ergens overheen kijken. Die blokhaken komen denk ik omdat ik zo lang bash scripts schrijf :D

Two advices for network troubleshooting.. learn to draw diagrams in Visio, and THINK IN LAYERS!


Acties:
  • +1 Henk 'm!

  • gekkie
  • Registratie: April 2000
  • Laatst online: 11-10 00:43
haakjes bij de if zijn in python uberhaupt redundant in dit geval.