Kieran Sinden
Kieran Sinden

Reputation: 1

.startswith using multiple variables

I am doing a project for school where I am making a cinema management system but I am a bit rusty with writing to/ reading from text files.

I have a list called lineStarters which contains string values "seatA", "seatB" etc etc.

later on in the project I use the line:

if line.startswith item in lineStarters and if "False" in line:
  line = line.replace("False","True")

This gives a syntax error.

To solve this I already tried a really long conditional statement. This didn't work either.Also it just wouldn't look good for my teacher.

tldr how would i go about using .startswith with multiple variables in Python.

Many thanks.

So I have a file called seatStatus which follows the format: seatA:False for each line. Say the cinema would have 10 seats there would be 10 line going from seatA to seatJ. lineStarters is an array with all of the starters of lines e.g seatA,seatB (for validation). False would mean that the seat is not booked so it would be like this by default until changed so for the applicable seats it would replace False (unbooked) to True (booked). Hope that makes sense. Thanks.

Upvotes: 0

Views: 112

Answers (1)

Vasilis G.
Vasilis G.

Reputation: 7844

If you want to check if your line starts with any of the seatA, seatB, etc, you can use any:

if any(line.startsWith(item) for item in lineStarters) and 'False' in line:

Upvotes: 2

Related Questions